【问题标题】:Why isn't anything showing in my Tkinter frame?为什么我的 Tkinter 框架中没有任何显示?
【发布时间】:2019-10-10 12:46:44
【问题描述】:

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

【问题讨论】:

标签: python python-3.x tkinter


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-02-16
    • 1970-01-01
    • 2023-01-21
    • 1970-01-01
    • 2019-04-28
    • 2021-11-16
    • 1970-01-01
    • 2018-09-08
    • 2021-05-15
    相关资源
    最近更新 更多