简体   繁体   English

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

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

I'm new to GUI programming and im trying to make my first GUI program, However.但是,我是 GUI 编程的新手,我正在尝试制作我的第一个 GUI 程序。 For some reason nothing will show on the frame.由于某种原因,框架上不会显示任何内容。 The frame is successfuly made, yet i cant show any image on it.框架已成功制作,但我无法在其上显示任何图像。 I've also tried making a button with no further success.我也尝试过制作一个没有进一步成功的按钮。 Sorry if this is something obvious, but like i earlier said i do not have any experiance with gui programming in python.抱歉,如果这是显而易见的事情,但就像我之前所说的,我没有在 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()

As it turns out, pycharm does not want to show images in a tkinter frame.事实证明,pycharm 不想在 tkinter 帧中显示图像。 The solution was then to save the Pycharm file and then run the script from cmd.解决方案是保存 Pycharm 文件,然后从 cmd 运行脚本。

I didnt worked with Images in Tkinter till now but try this:到目前为止,我没有使用 Tkinter 中的图像,但试试这个:

Display_icon.pack()

This should place your Display_icon on your root window.这应该将您的 Display_icon 放在您的根 window 上。

Hope this helps.希望这可以帮助。

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

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