Python 3中和Tkinter的通过点击该按钮打开新窗口 [英] Python 3 and tkinter opening new window by clicking the button
本文介绍了Python 3中和Tkinter的通过点击该按钮打开新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何打开一个新窗口,当用户点击的Tkinter和Python 3按钮?
How do I open a new window when the user clicks a button in Tkinter and Python 3?
推荐答案
您可以通过创建的Tkinter类的的Toplevel 。
You can open a new window by creating a new instance of the Tkinter class 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()
这篇关于Python 3中和Tkinter的通过点击该按钮打开新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文