[英]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.