[英]Tkinter: Window not showing image
我是 GUI 编程新手,最近开始使用 tKinter。
我的问题是程序不会显示我的图像,我怀疑是我的代码错误,但是,我希望有人能准确地向我解释我如何使它工作......
这是我的代码:
from tkinter import * # Import the tkinter module (For the Graphical User Interface)
from PIL import ImageTk, Image
width = 1920
height = 1080
RootGeo = str(width) + "x" + str(height) # Make a def for RootGeo so the Root geometry isn't hardcoded
def MakeWindow():
# -----Root_Attributes-----
Root = Tk()
Root.geometry(RootGeo)
Root.state("zoomed")
# -----Root_Attributes, Root_Containers----- ### NOT WORKING ###
__DISPlAY__ = Image.open("Display.png")
__DISPLAY_RENDER__ = ImageTk.PhotoImage(__DISPlAY__)
Display_icon = Label(Root, image=__DISPLAY_RENDER__)
Display_icon.image = __DISPLAY_RENDER__
Display_icon.place(x=0, y=0)
# -----Root_Containers----- ### NOT WORKING ###
Root.mainloop()
MakeWindow()
任何和所有的帮助将不胜感激。
尝试更改图像并检查它是否仍然没有出现。 如果它仍然没有出现,请尝试更改此行:
__DISPlAY__ = Image.open("Display.png")
至
__DISPlAY__ = Image.open("Display.png").resize((600,800))
看看它现在是否会显示,然后根据需要更改宽度和高度。
Pychamarm 不想显示图像,所以为了解决这个问题,我每次都必须从 cmd 运行脚本......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.