我想用Tkinter创建一个窗口。这个窗口应该有一个按钮。 按下按钮时,我想要出现第二个窗口(没有第一个窗口消失)。
代码缩短了:
from Tkinter import *
from modules.startingKit.highscore import Highscore
class OptionWindow:
def __init__(self):
self.master = Tk()
self.b4 = Button(self.master, text = "display Highscores", command = self.display()).grid(row=0, sticky = W)
mainloop()
def display(self):
myWin = Toplevel()
嗯,显示第二个窗口,但在按下按钮之前。我可以改变吗
答案 0 :(得分:6)
command
属性将引用带到函数中。当您执行command=self.display()
时,您调用该函数并将结果传递给command
属性。
修复是省略括号:
self.b4 = Button(..., command=self.display, ...)