Python (特金特)图像赢得';我不会出现在新窗口中

Python (特金特)图像赢得';我不会出现在新窗口中,python,tkinter,Python,Tkinter,我刚开始使用PythonTkinter,我有一个按钮可以打开一个新窗口。新窗口中有一个图像,但是图像不会显示。你能帮我解决我的问题吗 from tkinter import * def nwindow(): nwin = Toplevel() nwin.title("New Window") btn.config(state = 'disable') photo2 = PhotoImage(file = 'funny.gif') lbl2 = Labe

我刚开始使用PythonTkinter,我有一个按钮可以打开一个新窗口。新窗口中有一个图像,但是图像不会显示。你能帮我解决我的问题吗

from tkinter import *

def nwindow():
    nwin = Toplevel()
    nwin.title("New Window")
    btn.config(state = 'disable')

    photo2 = PhotoImage(file = 'funny.gif')
    lbl2 = Label(nwin, image = photo2)
    lbl2.pack()

def quit():
    nwin.destroy()
    btn.config(state = 'normal')

qbtn = Button(nwin, text = 'Quit', command = quit)
qbtn.pack()

main = Tk()
main.title("Main Window")
main.geometry("750x750")

photo = PhotoImage(file = 'funny.gif')
lbl = Label(main, image = photo)
lbl.pack()

btn = Button(main, text = "New Winodw", command = nwindow)
btn.pack()

main.mainloop()

您的编码不起作用,但是放置.mainloop()应该可以解决您的问题

def nwindow():
    nwin = Toplevel()
    nwin.title("New Window")
    btn.config(state = 'disable')

    photo2 = PhotoImage(file = 'funny.gif')
    lbl2 = Label(nwin, image = photo2)
    lbl2.pack()
    nwin.mainloop()

您的编码不起作用,但是放置.mainloop()应该可以解决您的问题

def nwindow():
    nwin = Toplevel()
    nwin.title("New Window")
    btn.config(state = 'disable')

    photo2 = PhotoImage(file = 'funny.gif')
    lbl2 = Label(nwin, image = photo2)
    lbl2.pack()
    nwin.mainloop()
这可能有用:这可能有用: