user-interface - Tkinter 中的多个窗口?

标签 user-interface tkinter

我是编程新手,很难找到教如何创建使用多个窗口的 GUI 的教程。例如,如果用户单击“查找”按钮,则会弹出一个包含搜索结果的窗口。我该如何实现这个目标?这在 Tkinter 中可能吗? 任何对来源的建议/引用将不胜感激。 谢谢。

最佳答案

要创建第一个窗口,您需要创建 Tk 类的实例。所有其他窗口都是 Toplevel 的实例。

import Tkinter as tk

class Example(tk.Frame):
    def __init__(self, root):
        tk.Frame.__init__(self, root)
        b1 = tk.Button(self, text="Add another window", command = self.newWindow)
        b1.pack(side="top", padx=40, pady=40)
        self.count = 0

    def newWindow(self):
        self.count += 1
        window = tk.Toplevel(self)
        label = tk.Label(window, text="This is window #%s" % self.count)
        label.pack(side="top", fill="both", expand=True, padx=40, pady=40);

if __name__ == "__main__":
    root = tk.Tk()
    Example(root).pack(side="top", fill="both", expand=True)
    root.mainloop()

关于user-interface - Tkinter 中的多个窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18342764/

相关文章:

java - 尝试在我的 java 应用程序中导入音频文件 : misplaced construct(s)

java - Android:出现软输入键盘时 Recyclerview 不调整大小

python - 用于 Python GUI 的强大表格小部件

java - 如何创建出现在程序最顶部的 Swing 菜单栏?

python - 如何设置tkinter框架的透明度?

python - Tkinter 清除消息小部件

python - 使用 matplotlib 从包含重复列名的 .csv 文件中绘图

python - 清除 Tkinter 条目文本 - 所以新文本看起来很新?

python - 控制 Tkinter 中滚动条的位置

python - Tkinter OptionMenu 参数