我正在开发在一个窗口中具有多个框架的项目,在p2框架中有多个按钮登录,注册,添加症状,edit_symptoms,delete_symptoms 。通过按一些按钮,应该在第p5帧上完成相应的操作(预期),但我无法重复使用第p5帧,请考虑是否按下按钮 login ,那么登录代码应显示在第5帧上p5,然后按 add_Symptoms 按钮,应删除先前的结构,并在同一帧p5中显示add_Symptoms的新代码。
from tkinter import *
root = Tk()
root.geometry("1280x730")
#define frames
p1 = Frame(root, background="#D3D3D3", borderwidth = 6,relief=RAISED)
p1.pack(side=RIGHT,fill="y")
p2 = Frame(root, background="#D3D3D3", borderwidth = 3,relief=RAISED)
p2.pack(side=TOP,fill="x")
p3 = Frame(root, background="#D3D3D3", borderwidth = 2,relief=SUNKEN)
p3.pack(side=TOP,fill="x")
p4 = Frame(root, background="white")
p4.pack(side=BOTTOM,fill="x")
p5 = Frame(root, borderwidth = 2)
p5.pack(side=LEFT,anchor="n")
#Funtions for button commands
def login():
p5.destroy() #Getting error here
label = Label(p5,text="Administrator Page",font=("Comic Sans MS",12,"italic"), fg = "red")
label.pack(padx=80,pady=10)
def add():
p5.destroy() #Getting error here
label = Label(p5,text="Add Symptomps",font=("Comic Sans MS",12,"italic"), fg = "green")
label.pack(padx=80,pady=10)
add_symptoms = Button(p1,text="Add Symptoms",command=add, state=DISABLED)
add_symptoms.pack(pady=10,padx=5)
login_admin = Button(p5,text="LOGIN",font=("Comic Sans MS",15,"italic"),fg="blue",command=login, width=15)
login_admin.pack(side=RIGHT, padx=25)
root.mainloop()
**Exception in Tkinter callback
Traceback (most recent call last):
File "c:\program files\python37\Lib\tkinter\__init__.py", line 1705, in
__call__
return self.func(*args)
File "project.py", line 67, in login
label = Label(p5,text="Administrator Page",font=("Comic Sans
MS",12,"italic"), fg = "red")
File "c:\program files\python37\Lib\tkinter\__init__.py", line 2766, in
__init__
Widget.__init__(self, master, 'label', cnf, kw)
File "c:\program files\python37\Lib\tkinter\__init__.py", line 2299, in
__init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError:错误的窗口路径名“。!frame5” **
答案 0 :(得分:0)
从登录p5.destroy()
中删除function
。之后,您销毁了框架,然后要将label = Label(p5,text="Administrator Page",font=("Comic Sans MS",12,"italic"), fg = "red")
包装在其中,这会导致错误。
我认为您应该看一下这个小部件toplevel,它是根窗口的从属窗口。
def login():
# p5.destroy() #Getting error here
label = Label(p5,text="Administrator Page",font=("Comic Sans MS",12,"italic"), fg = "red")
label.pack(padx=80,pady=10)