Python tkinter收回功能问题
我对python并不陌生,但也不擅长。我试图再次学习Tkinter,因为我完全忘记了它,哈哈,但我似乎被卡住了。你看,我正在制作一款文本冒险游戏,每次你点击一个按钮,它都应该是root。退出()窗口,创建一个新的具有新文本的窗口。当你点击它一次的时候效果很好,但是当你第二次尝试的时候,它没有任何帮助Python tkinter收回功能问题,python,tkinter,Python,Tkinter,我对python并不陌生,但也不擅长。我试图再次学习Tkinter,因为我完全忘记了它,哈哈,但我似乎被卡住了。你看,我正在制作一款文本冒险游戏,每次你点击一个按钮,它都应该是root。退出()窗口,创建一个新的具有新文本的窗口。当你点击它一次的时候效果很好,但是当你第二次尝试的时候,它没有任何帮助 root1.withdraw() police = Tk() police.geometry('300x500') l1 = Label(police, text='
root1.withdraw()
police = Tk()
police.geometry('300x500')
l1 = Label(police, text='You called the police who arrived\n on the scene within minutes. When they arrived they thankes you for not touching the body.\nWhat you didnt tell them is that you had touched the body.')
l1.grid(column=0, row=0)
def clicked1():
root.withdraw()
root1 = Tk()
root1.geometry('300x500')
l1 = Label(root1,
text='You enter your house after school only to find your \nmum dead on the carpet. There is blood everywhere.')
l1.grid(column=0, row=0, pady=30)
l2 = Label(root1, text=' ')
l2.grid(column=0, row=1)
l3 = Label(root1, text='What should you do?', pady=0)
l3.grid(column=0, row=2)
b1 = Button(root1, text='Call the police.', command=lambda: b1_call)
b1.grid(column=0, row=3, pady=10)
b2 = Button(root1, text='Investigate on your own.')
b2.grid(column=0, row=4, pady=10)
b3 = Button(root1, text='Leave it alone')
b3.grid(column=0, row=5, pady=10)
b1 = Button(root1, text='Call the police.')
b1.grid(column=0, row=3, pady=10)
提前感谢,,
Josh将所有这些root1重命名为root,然后再试一次可能
root1
是clicked1
函数中的一个局部变量,因此不在其外部定义。您可能想说global root1
,但除此之外,它永远不需要有超过1个Tk()的实例
因此,将所有子窗口替换为Toplevel()
,如果您试图打开隐藏窗口,请使用root1.deiconify()
,而不是创建Tk()的新实例。