-1

Before creating a post I tried to solve my problem by searching and reading through other users errors when it came to the "pyimage1" doesnt exist and i couldn't apply that to my code in order for it to work efficiently.

I'm not too sure what to try anymore at this point in order to get these buttons some photos! i've read through loads of threads from other people with the same problem but i just can't get it to work.

error code:

Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\korey\AppData\Local\Programs\Python\Python38\lib\tkinter__init__.py", line 1883, in call return self.func(*args) File "C:/Users/korey/PycharmProjects/test rental/gui test.py", line 186, in car_menu_screen Button(text="Coupe", height="15", width="75", command=login, image=coupephoto).place(x=420, y=220) File "C:\Users\korey\AppData\Local\Programs\Python\Python38\lib\tkinter__init__.py", line 2645, in init Widget.init(self, master, 'button', cnf, kw) File "C:\Users\korey\AppData\Local\Programs\Python\Python38\lib\tkinter__init__.py", line 2567, in init self.tk.call( _tkinter.TclError: image "pyimage1" doesn't exist

def car_menu_screen():
    global car_menu

    main_screen.destroy()  # Closes the main screen (login or register)
    car_menu = Tk()
    car_menu.geometry("1920x1080")  # Sets Window Size
    car_menu.title("Vehicle Choice Menu")  # Sets Window Title
    Label(text="What Type Of Vehicle Would You Like to Rent?", bg="red", width="300", height="2",
          font=("Arial Black", 13)).pack()
    Label(text="").pack()
    coupephoto = PhotoImage(file="coupe.png")
    sedanphoto = PhotoImage(file="sedan.png")
    suvphoto = PhotoImage(file="suv.png")
    sportsphoto = PhotoImage(file="sports.png")

    Button(text="Coupe", image=coupephoto, height="150", width="350", command=login).place(x=420, y=220)
    Label(text="").pack()
    Button(text="Sedan", image=sedanphoto, height="150", width="350", command=register).place(x=960, y=220)
    Label(text="").pack()
    Button(text="SUV", image=suvphoto, height="150", width="350", command=register).place(x=420, y=500)
    Label(text="").pack()
    Button(text="Sports", image=sportsphoto, height="150", width="350", command=register).place(x=960, y=500)
Pedram Parsian
  • 3,750
  • 3
  • 19
  • 34
white421
  • 1
  • 2
  • Did you tried defining `master` ? – shimo Feb 02 '20 at 01:38
  • im not quite sure how to define master – white421 Feb 02 '20 at 01:45
  • and im not too sure where to place it, i read on another thread to define master like this PhotoImage(master = canvas, width = WIDTH, height = HEIGHT) – white421 Feb 02 '20 at 01:46
  • Please try from simple example like this reddit sample. https://www.reddit.com/r/learnpython/comments/6ermnb/photoimage_in_python_361/didqb6k/ – shimo Feb 02 '20 at 01:47
  • i have read through the reddit post earlier before posting, couldn't get my head around it, it confuses me, i dont know where to put it in my code and what variables to put in – white421 Feb 02 '20 at 02:00
  • I have fiddled around with the code and managed to get it to run with no errors but i had a photo for one test and then i tried it again and it was gone, – white421 Feb 02 '20 at 02:32
  • I have just updated the code on the post, so i have managed to get 3 images to work, but when i try and implement the sportsphoto variable it causes the other photos not to show, so when i hash out the sportsphoto variable it will then show all of the other photos – white421 Feb 02 '20 at 02:37
  • Have you updated the error message you're receiving? – schwartz721 Feb 02 '20 at 03:16
  • Read [Why does Tkinter image not show up if created in a function?](https://stackoverflow.com/a/16424553/7414759). Relevant [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) and [Tkinter understanding mainloop](https://stackoverflow.com/questions/29158220/tkinter-understanding-mainloop) – stovfl Feb 02 '20 at 12:03

1 Answers1

0

Adding car_menu.mainloop() in the end of function worked.

I'm not sure but I got TclError: image "pyimage1" doesn't exist after an error which tk window does not open. This might be because I using Jupyter and resetting Jupyter worked fine.

from tkinter import*

def car_menu_screen():
    global car_menu

    main_screen.destroy()  # Closes the main screen (login or register)
    car_menu = Tk()
    car_menu.geometry("1920x1080")  # Sets Window Size
    car_menu.title("Vehicle Choice Menu")  # Sets Window Title
    Label(text="What Type Of Vehicle Would You Like to Rent?", bg="red", width="300", height="2",
          font=("Arial Black", 13)).pack()
    Label(text="").pack()
    coupephoto = PhotoImage(file="coupe.png")
    sedanphoto = PhotoImage(file="sedan.png")
    suvphoto = PhotoImage(file="suv.png")
    sportsphoto = PhotoImage(file="sports.png")

    Button(text="Coupe", image=coupephoto, height="150", width="350", command=login).place(x=420, y=220)
    Label(text="").pack()
    Button(text="Sedan", image=sedanphoto, height="150", width="350", command=register).place(x=960, y=220)
    Label(text="").pack()
    Button(text="SUV", image=suvphoto, height="150", width="350", command=register).place(x=420, y=500)
    Label(text="").pack()
    Button(text="Sports", image=sportsphoto, height="150", width="350", command=register).place(x=960, y=500)

    car_menu.mainloop()

car_menu_screen()

Here is my screenshot. (I commented out main_screen.destroy() for this.)

enter image description here

shimo
  • 2,156
  • 4
  • 17
  • 21
  • Awesome, i knew it had to be just down to a simple error! Thank you so much for you time and dedication it means a lot! – white421 Feb 02 '20 at 14:21