1

Good-day fellow programmers,I have code for a tkinter application but when I click on the login button to redirect me to a new page; my added images don't show but every other widget appears on screen.I am using python 3.7.4 and pycharm ide, All the images on the first window show perfectly,but its the second I've tried using toplevel to create a new window, still didn't work.Please i need help for this project.

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',font=('chiller',15),command=lambda: Add_to_cart())
        btn2.pack()

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

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

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

        btn4 = Button(f2, text='Remove from inventory', font=('chiller', 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,width=600,height=400)
f1.pack()
canvas=Canvas(f1,width=600,height=400)
my_image=ImageTk.PhotoImage(Image.open('C:/Users/Akinyemi Omodamilola/Downloads/car.jpg'))
canvas.create_image(0,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,width=25,textvar=Password,show='*')
pwd.place(x=250,y=200)
def passfoc():
    pwd.focus()


root.mainloop()
pylove
  • 11
  • 2
  • 1
    Read [Why does Tkinter image not show up if created in a function?](https://stackoverflow.com/a/16424553/7414759), this apply also to `lb9`. – stovfl Nov 05 '19 at 22:23

0 Answers0