我想知道self.pack(expand=1, fill="both")中self是root还是frame,没有这一句就无法显示,
有就可以显示
我这一共是几层frame,self.frame = Frame(self)是在root上还是在一个frame上面
class LoginInterface(Frame):
def __init__(self, parent,count_manager_dict):
super().__init__(parent)
self.count_manager_dict = count_manager_dict
self.pack(expand=1, fill="both")
self.frame = Frame(self)
self.frame.pack(expand=1, fill="both", padx=5, pady=5)
if __name__ == '__main__':
root = Tk()
root.title('员工考勤管理')
# root.state('zoomed')
interface = LoginInterface(root)
interface.run()
root.mainloop()
在将之前的类中执行self.destroy()销毁frame后
原窗口新建frame,下面类中self.pack(expand=1, fill="both")这一句代码有没有又都不影响显示,这又是为什么
class Manager(Frame):
def __init__(self, parent=None):
super().__init__(parent)
# self.pack(expand=1, fill="both")
self.frame = Frame(self)
self.frame.pack(expand=1, fill="both", padx=5, pady=5)
def __manager_view(self):
Label(text='manager').pack(expand=1,fill='both')
def run(self):
self.__manager_view()
self .frame.destroy()
self.destroy()
【1】第一段代码中,self
指实例化的LoginInterface
本身。
使用interface = LoginInterface(root)
后没有布局该控件,所以需要使用self.pack
(或self.place
,self.grid
)布局该控件。
【2】一共两个Frame:interface和self.frame(也就是interface.frame)。self.frame
在interface上,也就是self
上。
【3】代码中没有出现实例化Manager
类的代码,无法判断和解答你的问题。可能是该类实例化后进行了布局。
【4】第一行销毁的是interface.frame
,第二个销毁的是interface
。如果self是在类LoginInterface中的话。