在函数内调用函数不能正常工作

时间:2021-03-17 11:23:39

标签: python tkinter

我正在尝试从另一个函数中打开一个函数。当我分别运行这两个功能时,它们工作得很好。一旦我尝试从另一个功能中打开一个功能,它就会给我以下错误:

_tkinter.TclError: image "pyimage5" doesn't exist

这是两个函数:

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 函数

编辑:第一个问题已经解决

0 个答案:

没有答案
相关问题