2013-03-22 130 views
0

我想用Tkinter创建一个窗口。这个窗口应该有一个按钮。 当按下按钮时,我想要第二个窗口出现(没有第一个消失)。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() 

好,将显示第二个窗口,但在此之前我按下按钮。我可以更改这个

回答

6

command属性需要参考函数。当你做command=self.display()时,你是,调用函数并将结果传递给command属性。

解决方法是省略括号:

self.b4 = Button(..., command=self.display, ...) 
相关问题