Tkinter开发疑问:为何Element Frame无内容,仅Particle Frame正常?
问题原因及修复方案
你遇到的问题是复制代码时的粗心失误:编写Element Frame的控件时,所有控件的父容器都错误设为了particleFrame,而非elementFrame。这导致这些按钮、标签、输入框实际都被添加到了Particle Frame中,Element Frame本身是空的,切换过去自然看不到任何内容。
修正后的Element Frame代码:
# Element Frame elementFrame.grid_columnconfigure(0, weight=1) # 将父容器从particleFrame改为elementFrame BackButtonF3 = Button(elementFrame, text='Back', command=lambda: show_frame(Menu)) BackButtonF3.grid(row=0, column=0, sticky=W) ElementLabel = Label(elementFrame, text='testing', bg=LightBlue) ElementLabel.grid(row=1, column=0, pady=15) ElementEntry = Entry(elementFrame) ElementEntry.grid(row=2, column=0, pady=10) ElementEnter = Button(elementFrame, text='Enter', width=10) ElementEnter.grid(row=3, column=0, pady=10)
只需把Element Frame部分所有控件的第一个参数(父容器)从particleFrame替换为elementFrame,切换到Element Frame时就能正常显示内容了。
内容的提问来源于stack exchange,提问作者BluBalloon
相关产品推荐
相关产品推荐

