繁体   English   中英

为什么我的 Tkinter 框架中没有任何显示?

[英]Why isn't anything showing in my Tkinter frame?

但是,我是 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\Settings.gif"
    __DISPlAY__ = Image.open(__DISPLAY_DIRECTORY__).resize((50, 50))
    __DISPLAY_RENDER__ = ImageTk.PhotoImage(__DISPlAY__)

    Display_icon = Label(Root, image=__DISPLAY_RENDER__)
    Display_icon.pack()
    # -----Root_Containers----- ### NOT WORKING ###

    Root.mainloop()


MakeWindow()

事实证明,pycharm 不想在 tkinter 帧中显示图像。 解决方案是保存 Pycharm 文件,然后从 cmd 运行脚本。

到目前为止,我没有使用 Tkinter 中的图像,但试试这个:

Display_icon.pack()

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

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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