Python tkinter 创建两个窗口

标签 python python-3.x tkinter

我目前正在尝试使用 tkinter 程序创建两个窗口,但它似乎不起作用。直到最近,我才将我的游戏转移到 tkinter,这是第一次使用 tkinter。因此,我不知道为什么这不起作用。

这是我的第一个窗口,它工作正常

class Application(tk.Frame):
        def __init__(self, master=None):
            super().__init__(master)
            self.pack()
            self.create_widgets()
            self.crafting_listbox

虽然我的第二个窗口不工作

class Application_2(tk.Frame):
        def __init__(self, master=None):
            super().__init__(master)
            self.pack()
            self.crafting_listbox()

然后是收尾

 root = tk.Tk()
    app = Application(master=root)
    app.mainloop()

我不确定为什么这不起作用,出了什么问题?

最佳答案

你永远不会调用你的第二个框架。

要创建第二个窗口,请使用 Toplevel 类。

root = tk.Tk()
app = Application(master=root)

second_win = tk.Toplevel(root)
app2 = Application_2(second_win)

root.mainloop()

关于Python tkinter 创建两个窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44960702/

相关文章:

Python3 - 计算两个列表之间每对的出现次数

python - 如何创建 .desktop 文件以在 Linux 上启动 python 脚本?

python-3.x - python3 tkinter 或 ncurses

python-3.x - Control-Shift-Tab 的 Tkinter 键绑定(bind)

Python 在运行时意外执行命令

python - 在 Python 的测试包中运行单元测试

python - 使用 TF 2.0 提供 Tensorflow/Keras 模型时嵌入层的问题

python - Mysql fetchall方法抛出 "Unread result found"异常

python - 如何让Python的socket服务器永远运行

python - 为什么 NotImplemented 在 Python 3 中是真实的?