首页 > 解决方案 > 怎么不开窗

问题描述

from tkinter import *

def firstPage():
    def goSecond():
        root.destroy()
        secondPage()

    root = Tk()

    text = Label(root, text="1")
    text.pack()
    btn = Button(root, text="go to 2", command=goSecond)
    btn.pack()

    root.mainloop()

def secondPage():
    def goFirst():
        root.destroy()
        firstPage()

    root = Tk()

    text = Label(root, text="2")
    text.pack()

    btn = Button(root, text="go to 1", command=goFirst)
    btn.pack()

    root.mainloop()

firstPage()

我制作了这段代码,我希望它打开一个新页面,但它会打开一个新窗口,我明白为什么但我不知道如何打开页面而不是打开一个窗口。

标签: python-3.x

解决方案


推荐阅读