[英]Python 3 and tkinter opening new window by clicking the button
當用戶單擊Tkinter和Python 3中的按鈕時,如何打開新窗口?
您可以通過創建Tkinter類Toplevel的新實例來打開一個新窗口。
例如:
import Tkinter as tk
class View(tk.Frame):
count = 0
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
b = tk.Button(self, text="Open new window", command=self.new_window)
b.pack(side="top")
def new_window(self):
self.count += 1
id = "New window #%s" % self.count
window = tk.Toplevel(self)
label = tk.Label(window, text=id)
label.pack(side="top", fill="both", padx=10, pady=10)
if __name__ == "__main__":
root = tk.Tk()
view = View(root)
view.pack(side="top", fill="both", expand=True)
root.mainloop()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.