Мне не удается импортировать фотографию, поэтому она появляется на кнопке в моем приложении. "Pyimage1" не существует. - PullRequest
0 голосов
/ 02 февраля 2020

Перед созданием поста я пытался решить свою проблему путем поиска и чтения ошибок других пользователей, когда дело дошло до того, что «pyimage1» не существует, и я не мог применить это к своему коду, чтобы он работал эффективно.

Я не слишком уверен, что еще можно попробовать в данный момент, чтобы получить эти кнопки несколько фотографий! Я прочитал множество потоков от других людей с той же проблемой, но я просто не могу заставить ее работать.

код ошибки:

Исключение в обратном вызове Tkinter Traceback ( последний последний вызов): Файл "C: \ Users \ korey \ AppData \ Local \ Programs \ Python \ Python38 \ lib \ tkinter__init __. py", строка 1883, в вызов , возврат self.fun c (* args) Файл "C: / Users / korey / PycharmProjects / test rental / gui test.py", строка 186, в car_menu_screen Button (text = "Coupe", высота = "15", ширина = "75", команда = login, image = coupephoto) .place (x = 420, y = 220) Файл "C: \ Users \ korey \ AppData \ Local \ Programs \ Python \ Python38 \ lib \ tkinter__init __. Py ", строка 2645, в init Виджет. init (self, master, 'button', cnf, kw) Файл" C: \ Users \ korey \ AppData \ Local \ Программы \ Python \ Python38 \ lib \ tkinter__init __. Py ", строка 2567, в init self.tk.call (_tkinter.TclError: изображение" pyimage1 "не существует

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)

1 Ответ

0 голосов
/ 02 февраля 2020

Добавление car_menu.mainloop() в конец функции сработало.

Я не уверен, но я получил TclError: image "pyimage1" doesn't exist после ошибки, окно которой не открывается. Это может быть из-за того, что я использовал Jupyter и переустанавливал Jupyter нормально.

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()

Вот мой скриншот. (Я прокомментировал main_screen.destroy() за это.)

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...