[英]Tkinter: how to make window appear when a button is pressed
我想用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()
好吧,第二個窗口正在顯示,但是在我按下按鈕之前。 我可以改變這個嗎
command
屬性引用一個函數。 當執行command=self.display()
,您將調用該函數並將結果傳遞給command
屬性。
解決方法是省略括號:
self.b4 = Button(..., command=self.display, ...)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.