Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tkinter收回功能问题_Python_Tkinter - Fatal编程技术网

Python tkinter收回功能问题

Python tkinter收回功能问题,python,tkinter,Python,Tkinter,我对python并不陌生,但也不擅长。我试图再次学习Tkinter,因为我完全忘记了它,哈哈,但我似乎被卡住了。你看,我正在制作一款文本冒险游戏,每次你点击一个按钮,它都应该是root。退出()窗口,创建一个新的具有新文本的窗口。当你点击它一次的时候效果很好,但是当你第二次尝试的时候,它没有任何帮助 root1.withdraw() police = Tk() police.geometry('300x500') l1 = Label(police, text='

我对python并不陌生,但也不擅长。我试图再次学习Tkinter,因为我完全忘记了它,哈哈,但我似乎被卡住了。你看,我正在制作一款文本冒险游戏,每次你点击一个按钮,它都应该是root。退出()窗口,创建一个新的具有新文本的窗口。当你点击它一次的时候效果很好,但是当你第二次尝试的时候,它没有任何帮助

    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()的新实例。