【问题标题】:Button doesn't show in the frame按钮不显示在框架中
【发布时间】:2019-06-30 10:59:53
【问题描述】:

我创建了几个框架,现在想在它们上面放置一些按钮和标签,但是从我创建的第一个按钮开始,我遇到了问题。 tkinter 窗口中没有显示任何内容。

from tkinter import *

class STproject():

    def __init__(self,app): #1
        self.stframe=Frame(app,background='blue',height=90,width=350)
        self.stframe.grid(row=0,column=0)
        self.ndframe=Frame(app,background='red',height=90,width=350)
        self.ndframe.grid(row=1,column=0)
        self.rdframe=Frame(app,background='yellow',height=90,width=350)
        self.rdframe.grid(row=2,column=0)

        self.ndstframe=Frame(self.ndframe,background='black',width=145)
        self.ndstframe.grid(row=0,column=0,rowspan=3,sticky='ns')
        self.ndndframe=Frame(self.ndframe,background='white',height=45,width=205)
        self.ndndframe.grid(row=1,column=1)
        self.ndrdframe=Frame(self.ndframe,background='green',height=45,width=205)
        self.ndrdframe.grid(row=2,column=1)

    def buttons(self):
        self.importbutton=Button(self.stframe,text='Import',width=4,height=2)
        self.importbutton.grid(row=0,column=0)



root=Tk()
root.title('SteelBox Inc. Calculator')
application=STproject(root) #2
root.mainloop() #3

【问题讨论】:

    标签: python python-3.x button tkinter frame


    【解决方案1】:

    您已将按钮的创建放在一个单独的函数中,但您从未调用它。 在__init__末尾添加self.buttons(),就会出现按钮。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 2013-03-29
      • 1970-01-01
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多