简体   繁体   中英

Tkinter: Window not showing image

I am new to GUI programming and recently started working with tKinter.

My problem is that the program won't show my image, I'm suspecing that it is my code that is wrong, however, I would like somone to exactly explain to me how i can make it work...

Here's my code:

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

Any and all help would be very appreciated.

try to change the image and check out if its still not showing up. if its still not showing up, try to change this line:

__DISPlAY__ = Image.open("Display.png")

to

__DISPlAY__ = Image.open("Display.png").resize((600,800))

see if it would show up now then change the width and height as you like.

Pychamarm does not want to show the images, so to solve this problem i had to run the script from cmd every time...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM