I want to display an image with the tkinter module, but I can't do it well.
Moreover, there was no error, just the canvas came out and the image was not displayed.
What I tried
from tkinter import * tk = Tk () tk.title ("1 + 1 = 3") tk.resizable (0,0) # Determine the size of the window. tk.wm_attributes ("-topmost", 1) # Bring the game screen to the top canvas = Canvas (tk, width = 1430, height = 800, bd = 0, highlightthickness = 0) canvas.pack () tk.update () hai = PhotoImage ("/ Users/username/Desktop/python/background.gif") canvas.create_image (0,0, anchor = NW, image = hai)
I changed the location of PhotoImage to /Users/username/background.gif, but it didn't change.
I confirmed it with the os module, so I think there is no doubt.
Also, I tried to name the image in English, but it didn't change.
I am using IDLE of python and the version is the latest.
Also, the personal computer uses a macbook.
Answer # 1
The drawing is reflected when the tkinter event loop is running, so
tk.mainloop ()Try to call at the end
Also, when writing the entire code inside a function
Also note the lifetime of the variable that stores the PhotoImage.
It is destroyed by the destructor and there is no error
The image may not be displayed either, so you need to keep it somewhere.
- image cannot be displayed with python tkinter
- matplotlib - the image of matplot is displayed on the gui of tkinter, but i want to display the histogram in a separate window
- python - tkinter photo image question
- python - image is not displayed with skimageioshow ()
- how to save the image ocr result file in python
- python - [tkinter] [py installer] unable to execute exe file
- python - image recognition with keras
- css3 - about the optimum image size to be displayed on the web
- python - reopening the file dialog in tkinter results in an error
- unable to call python module
- python - image is not saved even though there is no opencv error
- python - object is not displayed in html in django queryset
- python - about image deletion in django
- [python] [tkinter] i want to change the acquisition contents of the second and subsequent menu lists by selecting the previous p
- python 3x - unintended behavior of python3 tkinter binding
- in [python] print (), if a scatter plot is displayed using a one-dimensional array that has the intended values, the distributio
- ruby - s3 image is not displayed (activestorage)
- python 3x - change font size for python3 tkinter entry
- python3 tkinter i want to be able to input only character strings in a fixed format
- python : how to find out the size of a Tkinter window?
- python : Frame.destroy () does not remove Frame and ttk.Progressbar does not appear
- python : aiogram does not work as expected
- python : Text selection event in TKinter
- Python tkinter center frame between two others which are under side= left and side= right
- Tkinter error when using gif animation in python. ("after" script)
- python : Strange tkinter error '_tkinter.TclError: bitmap "pyimage1" not defined'
- python : How to replace tabs (\ t) with 4 spaces in Tkinter
- python : The game does not open again
- python : How to create a window to display the result?