Python 在函数中调用函数不能正常工作

Python 在函数中调用函数不能正常工作,python,tkinter,Python,Tkinter,我试图从另一个函数中打开一个函数。当我分别运行这两个函数时,它们工作得非常好。当我尝试从另一个函数中打开其中一个函数时,会出现以下错误: \u tkinter.TclError:图像“pyimage5”不存在 这是两个功能: def ah(): root=Tk() root.geometry('400x400') root.title('Results') root.minsize(400,400) root.maxsize(400,400) b

我试图从另一个函数中打开一个函数。当我分别运行这两个函数时,它们工作得非常好。当我尝试从另一个函数中打开其中一个函数时,会出现以下错误:

\u tkinter.TclError:图像“pyimage5”不存在

这是两个功能:

def ah():
    root=Tk()
    root.geometry('400x400')
    root.title('Results')
    root.minsize(400,400)
    root.maxsize(400,400)

    bg= PhotoImage(file='D:/Informatica eindopdracht/achtergrond.png')
    label=Label(root, image=bg)
    label.place(x=0, y=0, relwidth=1, relheight=1)

    close= Button(uitslag, text='Afsluiten', bd='5', height='2', width='15', command=root.destroy())
    close.place(x=0, y=353)

    mainloop()

def nextwin():
    global volgendeR
    
    def count():
        menu.counter += 1
        
    count()
        
    if menu.counter == rounds:
        nextwin.destroy()
    else:
        result=Button(spelmenu, text="Next round", bd='5', height='2', width='15', command=spelmenu()
        result.place(x=150, y=350)
在已存在的窗口中调用nextwin()函数。因此,此函数没有
root=Tk()
。结果按钮中提到的spelmenu窗口是一个不同的窗口,其中包含游戏的其余部分。链接到命令的函数也是如此。这根本不是问题

我使用以下功能通过用户输入获取轮数:

def nameANDround():
    global rondes

    w = Tk()
    w.geometry('600x600')
    w.title('Pick a name')
    w.minsize(400, 400)
    w.maxsize(400, 400)

    naam1Label=Label(w, text="Player 1")
    naam2Label=Label(w, text="Player 2")
    naam3Label=Label(w, text="Player 3")
    rondesLabel=Label(w, text="Rounds")
    
    naam1Label.place(x=100, y=120)
    naam2Label.place(x=100, y=140)
    naam3Label.place(x=100, y=160)
    rondesLabel.place(x=67, y=178)

    Naam1=Entry(w)
    Naam2=Entry(w)
    Naam3=Entry(w)
    rounds=Entry(w)
    
    Naam1.place(x=145, y=120)
    Naam2.place(x=145, y=140)
    Naam3.place(x=145, y=160)
    rounds.place(x=145, y=180)

    save=Button(w, height=1, width=10, text='Opslaan', command=nummer)
    save.place(relx=0.5, rely=0.72, anchor=CENTER)

    Naam1_var=StringVar()
    Naam2_var=StringVar()
    Naam3_var=StringVar()
    
    mainloop()
链接到“保存”按钮的命令是一个检查舍入输入是否为整数的函数。剩下的两个问题是:

1。如何从nextwin()函数中打开ah()函数,而不给我一个错误。

2。如何使if…else函数在nextwin()函数中正常工作。它当前正在忽略if或else函数


编辑:第一个问题已解决

此问题通常是由多个Tk实例引起的。将
ah
中的
root=Tk()
更改为
root=Toplevel()
@Henry很抱歉回复太晚了。我将它改为
root=Toplevel()
,现在它的功能与我所希望的一样。现在我只剩下第二个问题了。你对如何解决这个问题有什么想法吗?每个问题应该只有一个问题,并且只有重现该问题所涉及的特定问题所需的最短代码。无论如何——我建议在问题2所涉及的比较旁边记录实际值的
repr()
(或设置调试器断点)然后检查变量的实际值,看看为什么条件没有按您期望的方式计算。我不确定第二个变量有什么问题,抱歉