【问题标题】:tkinter.TclError: image "pyimage2" doesn't existtkinter.TclError:图像“pyimage2”不存在
【发布时间】:2019-11-20 13:38:33
【问题描述】:

所以,我的项目有 3 个窗口,我希望这 3 个窗口具有每个背景图像,但我不知道如何解决这个问题,现在已经花了好几个小时了。这是我的代码..

def Registration():

rootA = Toplevel() # This creates the window, just a blank one.
    rootA.geometry("1366x768")
    rootA.configure(background="black")
    rootA.title('Registation') # This renames the title of said window to 'signup'
    rootA.attributes('-fullscreen', True)

    image3=Image.open('2.gif')
    image4=ImageTk.PhotoImage(image3)
    image3_label=Label(borderwidth=0)
    image3_label.grid(column=0,row=0)

    registrationLabel = Label(rootA, image=image4)
    registrationLabel.place(x=0,y=0)

    fnameEntry= Entry(rootA)
    fnameEntry.place(x=680,y=350,width=200)

def Login():
    global nameEL
    global pwordEL
    global rootA

    rootA = Tk() 
    rootA.geometry("1366x768")
    rootA.configure(background="black")
    rootA.attributes('-fullscreen', True)
    rootA.title('Food Delivery') # This makes the window title 'login'

    image2=Image.open('1.gif')
    image1=ImageTk.PhotoImage(image2)
    image2_label=Label(borderwidth=0)
    image2_label.grid(column=0,row=0)

    titleLabel = Label(rootA, image=image1)
    titleLabel.place(x=0,y=0)

# ====== 这部分现在是我的问题。

def CheckLogin():
    with open(creds) as f:
        data = f.readlines() 
        username = data[0].rstrip()
        password = data[1].rstrip()

    if nameEL.get() == username and pwordEL.get() == password: 
        #r = Tk() # Opens new window
        #r.title('Food Delivery')
        #r.geometry('100x80')
        #r.title("Food Delivery")
        #r.configure(background='pink')

I mean, this part I just label it Tk cos I don't know what to do.

        rootA = Tk() 
        rootA.geometry("1366x768")
        rootA.configure(background="black")
        rootA.attributes('-fullscreen', True)
        rootA.title('Food Delivery') 

        image2=Image.open('4.gif')
        image1=ImageTk.PhotoImage(image2)
        image2_label=Label(borderwidth=0)
        image2_label.grid(column=0,row=0)

# #我不知道下一步是什么或正确的代码。提前致谢

【问题讨论】:

    标签: python-3.x tkinter tkinter-canvas


    【解决方案1】:

    您一次只能拥有一个Tk 实例。如果您需要其他窗口,请创建 Toplevel 的实例。

    Tk 的每个实例都与其他实例隔离。在其中一个中创建的变量、小部件和图像在其他中不可见。

    【讨论】:

    • 那么,对于我的第三个窗口,我可以再次使用顶层吗?
    • 我已经为我的第三个窗口再次尝试了顶层,它可以工作并且没有错误,但图像不可见。如何显示图像?非常感谢,伙计!
    猜你喜欢
    • 2014-11-23
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 2022-11-29
    • 2023-02-07
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    相关资源
    最近更新 更多