Tkinter: Window not showing image

2024/9/20 10:47:52

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

Here's my code:

from tkinter import *  # Import the tkinter module (For the Graphical User Interface)
from PIL import ImageTk, Imagewidth = 1920
height = 1080
RootGeo = str(width) + "x" + str(height)  # Make a def for RootGeo so the Root geometry isn't hardcodeddef 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.

Answer

try to change the image and check out if its still not showing up. if its still not showing up, try to change this line:

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

to

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

see if it would show up now then change the width and height as you like.

https://en.xdnf.cn/q/119378.html

Related Q&A

print dictionary minus two elements

Python 3.6All debug output is from PyCharm 2017.1.2I have a program that gets to this portion of the code:if len(errdict) == 21:for k, v in errdict.items():if k == packets output or bytes:continueprint…

Write CSV file using Python with the help of a csv dictionary / nested csv dictionary

I am having a csv file and i want to write it to another csv file. Its a bit complicated than it seems. Hoping someone to correct my code and rewrite it, so that i can get the desired csvfile. I am usi…

saving data to txt file using python

I am new in python, and I really need some help. I am doing this memory game where I need to save user, game score and time into a text file using python. I have tried several ways to do it, but nothin…

How can I create bounding boxes/contour around the outer object only - Python OpenCV

So Ive been trying to make bounding boxes around a couple of fruits that I made in paint. Im a total beginner to opencv so I watched a couple tutorials and the code that I typed made, makes contours ar…

resuming download file ftp python3.*

There is a file (1-7Gb) that you need to pick up. The network periodically falls, so it is necessary to implement the method of resume. For example, in 1 communication session downloaded 20% the networ…

printing files based on character

I have a directory(data) that contain thousand of files.Each time I want to select three files that are just differ by only one characterAB[C,D,E] and want to perform some computation on the selected t…

Parsing CSV file using Panda

I have been using matplotlib for quite some time now and it is great however, I want to switch to panda and my first attempt at it didnt go so well.My data set looks like this:sam,123,184,2.6,543 winte…

Getting division by zero error with Python and OpenCV

I am using this code to remove the lines from the following image:I dont know the reason, but it gives me as output ZeroDivisionError: division by zero error on line 34 - x0, x1, y0, y1 = (0, im_wb.sha…

Pandas complex calculation based on other columns

I have successfully created new columns based on arithmetic for other columns but now I have a more challenging need to first select elements based on matches of multiple columns then perform math and …

how to generate word from a to z [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…