python - 我无法导入照片,因此它会出现在我的应用程序“pyimage1”不存在的按钮上
问题描述
在创建帖子之前,我尝试通过搜索和阅读其他用户错误来解决我的问题,当涉及到“pyimage1”不存在时,我无法将其应用于我的代码以使其有效工作。
我不太确定此时该尝试什么才能让这些按钮获得一些照片!我已经阅读了其他有同样问题的人的大量线程,但我无法让它工作。
错误代码:
Tkinter 回调 Traceback 中的异常(最近一次调用最后一次):文件“C:\Users\korey\AppData\Local\Programs\Python\Python38\lib\tkinter__init__.py”,第 1883 行,调用 返回 self.func(*args ) 文件“C:/Users/korey/PycharmProjects/test rental/gui test.py”,第 186 行,在 car_menu_screen 按钮中(text="Coupe", height="15", width="75", command=login, image=coupephoto).place(x=420, y=220) 文件“C:\Users\korey\AppData\Local\Programs\Python\Python38\lib\tkinter__init__.py”,第 2645 行,在init Widget 中。init (self, master, 'button', cnf, kw) 文件“C:\Users\korey\AppData\Local\Programs\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)
解决方案
在函数末尾添加car_menu.mainloop()
有效。
我不确定,但我得到了TclError: image "pyimage1" doesn't exist
一个错误,tk 窗口没有打开。这可能是因为我使用 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()
。)
推荐阅读
- python - 访问嵌套列表项并在不规则列表中打印某些索引
- c - 当我们传递一个指向单个字符的 char * 时,%s 在 C 中的行为如何
- http - 快速路由路径在生产中不起作用
- python - 如何格式化cmd输出并将其附加到reportlab PDF
- java - 由于新项目中的 values.xml,Android 资源编译失败
- angular - 无法在 Chrome 上打开 base64 pdf
- javascript - 在 Chrome 中取消 onbeforeunload 模块窗口后显示自定义确认窗口
- angular - 在没有 sharedModule 的多个模块中使用自定义管道
- android - java.lang.IllegalStateException:不应为错误类型创建 SimpleTypeImpl
- node.js - 将 Node 应用部署到 Google Cloud App Service - 如何编辑我的代码?