为什么在我的Tkinter框架中什么都没有显示?

问题描述 投票:0回答:1

我是GUI编程的新手,但是我试图制作我的第一个GUI程序。由于某些原因,框架上将不会显示任何内容。框架制作成功,但我无法在其上显示任何图像。我也尝试过制作按钮,但没有成功。抱歉,这很明显,但是就像我之前说的,我对使用python进行gui编程没有任何经验。

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_DIRECTORY__ = "C:\Users\Gotta\PythonProjects\AutoCam\Display.png"
    __DISPlAY__ = Image.open(__DISPLAY_DIRECTORY__).resize((50, 50))
    __DISPLAY_RENDER__ = ImageTk.PhotoImage(__DISPlAY__)

    Display_icon = Label(Root, image=__DISPLAY_RENDER__)
    Display_icon.image = __DISPLAY_RENDER__
    Display_icon.plave(x=0, y=0)
    # -----Root_Containers----- ### NOT WORKING ###

    Root.mainloop()


MakeWindow()
python python-3.x tkinter
1个回答
-1
投票

到目前为止,我还没有在Tkinter中处理过Images,但是请尝试以下操作:

Display_icon.pack()

这应该将您的Display_icon放在您的根窗口上。

希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.