我想为TopLevel设置标题,但TopLevel显示根的标题。我认为我的下一个脚本与TkInter文档中的示例相对应,但给了我一个糟糕的结果。你能给我解释一下,为什么我的设置硕士学位=类AppTop中的'Top'不为TopLevel设置新标题?你知道吗
import tkinter as tk
class AppTop(tk.Frame):
def __init__(self, master):
mon_h = 900
mon_w = 1250
master.title = 'Top'
tk.Frame.__init__(self, master)
master.minsize(height = 900, width = 600)
fr_button = tk.Frame(master)
fr_button.place(relx=0.01, rely=0.06)
butArrowPlus = tk.Button(fr_button, text=">", height = 1, width = 20, command=self.Cmd)
butArrowPlus.grid(column= 1, row= 1)
return
def Cmd(self):
return
class Application(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
frRoot = tk.Frame(master, width=700, height=400, bd=2)
frRoot.place(relx=0.1, rely=0.1, anchor="nw")
butIllumBall = tk.Button(frRoot, text= 'Light Ball', height = 1, width = 20, command=self.cmd_illuminated_ball)
butIllumBall.grid(column= 0, row= 0, pady=10)
master.minsize(height = 250, width = 300)
master.title('Root')
def cmd_illuminated_ball(self):
top = tk.Toplevel()
top.transient(self.master)
top.grab_set()
app = AppTop(master = top)
app.mainloop()
return
wndRoot = tk.Tk()
appapp = Application(master=wndRoot)
appapp.mainloop()
您尝试设置顶级标题:
但正确的语法是:
另外还有两件事:顶层窗口不需要额外的主循环。从代码上看,似乎您认为顶层是一个新的应用程序,用
app = AppTop(master = top)
实例化它。但它只是一个在appapp.mainloop()
下运行的新窗口。你知道吗AppTop()
继承自tk.框架()但你从不使用它。相反,您将所有小部件直接放在顶级(主)窗口中。这同样适用于Application()
。你知道吗相关问题 更多 >
编程相关推荐