Oct-25-2019, 01:17 PM
(This post was last modified: Oct-25-2019, 01:17 PM by SomeRandomGuy.)
I'm searching the internet for like 2 hours now and can't find any solutions. I tried multiple images, converted them to .png, .gif and others, but nothing seems to work. I even tried to use Pillow at some point, but it resulted in "_tkinter.TclError: couldn't open "<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=24x24 at 0x73C970>": no such file or directory" error all the time. I even thought the size might be the issue, so I tried to rescale the images multiple times, but nothing works.
I use "def firstGUI():" for "faster access" later on so I can just open GUIs whenever I need to.
characterwindow01.jpg image is "stolen" from a game called Titan Quest, but only temporarily till I learn how to manage GUIs. I just felt that it looks quite good as a learning image as it has plenty of space to toy with.
I use Python 3.7, as I didn't really bother updating it for some reason.
Newest version of PyCharm is on duty! Using version 2019.2.3.
I am on Windows 7
If I forgot to include something, please tell me. I used the help (https://python-forum.io/misc.php?action=help) but I might've overlooked something.
import tkinter as tk w, h = (864, 576) root = tk.Tk() def firstGUI(): canvas = tk.Canvas(root, height=h, width=w) canvas.pack() bg = tk.PhotoImage(file="characterwindow01.jpg") bg_l = tk.Label(root, image=bg) bg_l.place() firstGUI() root.mainloop()With this script, I get the error "_tkinter.TclError: couldn't recognize data in image file "characterwindow01.jpg"" and I don't know what to search or do anymore. I am quite new to Python (or more like old but I keep "abandoning" Python every now and then because I program strictly for myself and only when I need something), so try to explain as much as possible, if you don't mind.
I use "def firstGUI():" for "faster access" later on so I can just open GUIs whenever I need to.
Error:C:\Users\Admin\firstgui\Scripts\python.exe "D:/Program Files/python projects/firstgui/GUI.py"
Traceback (most recent call last):
File "D:/Program Files/python projects/firstgui/GUI.py", line 17, in <module>
firstGUI()
File "D:/Program Files/python projects/firstgui/GUI.py", line 12, in firstGUI
bg = tk.PhotoImage(file="characterwindow01.jpg")
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 3545, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 3501, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "characterwindow01.jpg"
Process finished with exit code 1
Additional info:characterwindow01.jpg image is "stolen" from a game called Titan Quest, but only temporarily till I learn how to manage GUIs. I just felt that it looks quite good as a learning image as it has plenty of space to toy with.
I use Python 3.7, as I didn't really bother updating it for some reason.
Newest version of PyCharm is on duty! Using version 2019.2.3.
I am on Windows 7
If I forgot to include something, please tell me. I used the help (https://python-forum.io/misc.php?action=help) but I might've overlooked something.