我创建了一个主窗口,当单击B1按钮时,应该使用object.place_forget,object.pack_forget删除帧,以便稍后我可以创建一个新窗口。但是我收到错误消息。
文件" ./ trial.py",第60行,在设置中 self.Data_frame.pack_forget() AttributeError:Gui实例没有属性' Data_frame'
#! /usr/bin/python
from Tkinter import *
class Gui(Frame):
def __init__(self,parent):
Frame.__init__(self,parent)
# p_height=480
# p_width =720
self.parent=parent
self.topframe=Frame(self.parent, bg = "black")
self.topframe.config(highlightbackground='cyan',highlightthickness='2')
self.topframe.pack()
self.topframe.place(x=0,y=0,anchor=NW,height=480,width=720)
self.Info_frame=Frame(self.parent, bg="#222")
self.Info_frame.config(highlightbackground='black',highlightthickness='5')
self.Info_frame.pack()
self.Info_frame.place(x=5,y=5,height=50,width=710)
label=Label(self.Info_frame,text="Main Screen",bg="#222",fg="cyan",font=("Helvetica",20))
label.pack()
# label.place(x=260,y=0)
self.Data_Frame=Frame(self.parent, bg = "cyan")
self.Data_Frame.pack()
self.Data_Frame.place(x=5,y=50,anchor=NW,height=390,width=525)
self.Data_Frame.config(highlightbackground='black',highlightthickness='5')
l1=Label(self.Data_Frame,text="L1",width=20,bg="cyan",anchor=NW,font=("Helvetica", 15))
l1.place(x=13,y=10)
l2=Label(self.Data_Frame,text="L2",width=20,bg="cyan",anchor=NW,font=("Helvetica", 15))
l2.place(x=13,y=40)
l3=Label(self.Data_Frame,text="L3",width=20,bg="cyan",anchor=NW,font=("Helvetica", 15))
Nav_Frame=Frame(self.parent,bg="cyan")
Nav_Frame.place(x=525,y=50,anchor=NW,height=390,width=190)
Nav_Frame.config(highlightbackground='black',highlightthickness='5')
b1=Button(Nav_Frame,text="B1",width=12,bd=2,fg="cyan",font=("Helvetica", 15),command=self.setup)
b1.pack()
b2=Button(Nav_Frame,text="B2",width=12,bd=2,fg="cyan",font=("Helvetica", 15),command=self.setup)
b2.pack()
b3=Button(Nav_Frame,text="B3",width=12,bd=2,fg="cyan",font=("Helvetica", 15),command=self.setup)
b3.pack()
Bot_Frame=Frame(self.parent,bg="#222")
Bot_Frame.place(x=5,y=425,anchor=NW,height=50,width=710)
Bot_Frame.config(highlightbackground='black',highlightthickness='5')
def setup(self):
self.Data_frame.pack_forget()
self.Data_frame.place_forget()
self.Info_frame.place_forget
self.nfo_frame.pack_forget
if __name__== "__main__":
root = Tk()
root.attributes('-fullscreen',True)
#root.config(cursor="none")
app=Gui(root)
app.mainloop()
答案 0 :(得分:1)
大写F
,Data_Frame
不是Data_frame
。您还错过了I
中的Info_Frame
,而您没有调用方法::
def setup(self):
self.Data_Frame.pack_forget()
self.Data_Frame.place_forget()
self.Info_frame.place_forget() # call
self.Info_frame.pack_forget() # self.Info_frame not self.nfo_frame
如果你做出这些改变,一切都会奏效。