【问题标题】:Tkinter: Window not showing imageTkinter:窗口不显示图像
【发布时间】:2019-10-05 15:00:53
【问题描述】:

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

我的问题是程序不会显示我的图像,我怀疑是我的代码有问题,但是,我希望有人能准确地向我解释我如何使它工作......

这是我的代码:

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

我们将不胜感激任何和所有的帮助。

【问题讨论】:

  • 不是重复的......
  • @BryanOakley 对不起,如果我弄错了,但是我不明白那个帖子,有人可以详细解释一下吗?
  • 我错了。我删除了我之前的评论。
  • @BryanOakley 好的...但是你能解释一下出了什么问题吗?

标签: python python-3.x user-interface tkinter


【解决方案1】:

尝试更改图像并检查它是否仍然不显示。 如果它仍然没有出现,请尝试更改此行:

__DISPlAY__ = Image.open("Display.png")

__DISPlAY__ = Image.open("Display.png").resize((600,800))

看看它现在是否会显示,然后根据需要更改宽度和高度。

【讨论】:

  • 图片连显示都没有,目录是正确的
  • 到底发生了什么? cmd是返回错误,还是出现没有图片的窗口?
  • 是的。出现一个没有任何错误的窗口,但没有显示图像,
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-02
    • 1970-01-01
    • 2019-03-04
    • 2019-02-06
    • 1970-01-01
    • 2019-01-02
    • 2014-06-27
    相关资源
    最近更新 更多