本文介绍了Tkinter:窗口不显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 GUI 编程的新手,最近开始使用 tKinter.

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...

这是我的代码:

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.

推荐答案

Pychamarm 不想显示图像,所以为了解决这个问题我每次都必须从 cmd 运行脚本...

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

这篇关于Tkinter:窗口不显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:58