第二个tkinter窗口不添加图像

程序员程序员,我好,我有一个tkinter应用程序的代码,但是当我单击登录按钮将我重定向到新页面时;我添加的图像没有显示,但其他所有小部件都显示在屏幕上。我正在使用python 3.7.4和pycharm ide,第一个窗口中的所有图像均显示完美,但第二个窗口中我尝试使用顶级创建新窗口窗口,仍然没有用。请为这个项目寻求帮助。

from tkinter import *
from tkinter import messagebox
from PIL import ImageTk,Image


def login_page():
    username=user.get()
    Password=pwd.get()
    if Password=="" and username=="":
        f1.forget()
        f2=Frame(root,width=600,height=400,bg='#249493')
        f2.pack()
        my_image5 = ImageTk.PhotoImage(Image.open('C:/Users/Akinyemi 
                    Omodamilola/Downloads/cart.png'))
        lb9 = Label(root,image=my_image5)


        space = Label(f2,bg='#249493')
        space.pack()

        lb5 = Label(f2,text="Welcome  " + username,font=('chiller',30),fg='white',bg='#249493')
        lb5.pack()

        space = Label(f2,bg='#249493')
        space.pack()

        btn2=Button(f2,text='Add to Inventory',15),command=lambda: Add_to_cart())
        btn2.pack()

        space=Label(f2,bg='#249493')
        space.pack()

        btn3 = Button(f2,text='Edit Inventory',)
        btn3.pack()

        space = Label(f2,bg='#249493')
        space.pack()

        btn4 = Button(f2,text='Remove from inventory',15))
        btn4.pack()
    elif Password=="" or username=="":
        messagebox.showinfo("Alert","Type complete parameters")
    else:
        messagebox.showinfo("Alert","Wrong input")
return

root = Tk()
f1=Frame(root,height=400)
f1.pack()
canvas=Canvas(f1,height=400)
my_image=ImageTk.PhotoImage(Image.open('C:/Users/Akinyemi Omodamilola/Downloads/car.jpg'))
canvas.create_image(0,anchor=NW,image=my_image)
canvas.place(x=0,y=0)

root.title("Airwhips shop")
root.geometry("600x400")
root.resizable(0,0)
root.iconbitmap('C:/Users/Akinyemi Omodamilola/Downloads/favicon.ico')
f=Frame(f1,width=400,height=200,bg="white")
f.place(x=100,y=100)

#button
btn = Button(f1,text="Login",width=10,height=1,bg="black",fg="white",bd=0,command=lambda:login_page())
btn.place(x=285,y=250,bordermode="inside")

root.bind('<Return>',lambda event: login_page())
root.bind('<Down>',lambda event: passfoc())



my_image1=ImageTk.PhotoImage(Image.open('C:/Users/Akinyemi Omodamilola/Downloads/user.png'))
lb2=Label(f1,image=my_image1)
lb2.place(x=200,y=160)


my_image2=ImageTk.PhotoImage(Image.open('C:/Users/Akinyemi Omodamilola/Downloads/padlock.png'))
lb3=Label(f1,image=my_image2)
lb3.place(x=200,y=200)



lb=Label(f1,text="Admin Login",font=("chiller",14),fg="black",bg="white")
lb.place(x=250,y=100)

#entry
username=StringVar()
Password=StringVar()


user=Entry(f1,width=25,textvar=username)
user.place(x=250,y=160)
user.focus()
pwd=Entry(f1,textvar=Password,show='*')
pwd.place(x=250,y=200)
def passfoc():
    pwd.focus()


root.mainloop()
yingchenlu 回答:第二个tkinter窗口不添加图像

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3156094.html

大家都在问