Python Forum
tkInter and Pillow don't display any images in GUIs - program gives errors instead
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkInter and Pillow don't display any images in GUIs - program gives errors instead
#1
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.

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


Messages In This Thread
tkInter and Pillow don't display any images in GUIs - program gives errors instead - by SomeRandomGuy - Oct-25-2019, 01:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems trying to position images with Tkinter emont 3 878 Dec-12-2023, 07:20 AM
Last Post: menator01
  [PyGUI] GUIS Gibbse16 1 22,090 Mar-20-2021, 09:43 PM
Last Post: deanhystad
  [Tkinter] Noob question:Using pyttsx3 with tkinter causes program to stop and close, any ideas? Osman_P 4 5,385 Nov-14-2020, 10:51 AM
Last Post: Osman_P
  How to display results from terminal window onto tkinter. buttercup 0 3,688 Jul-21-2020, 04:41 AM
Last Post: buttercup
  [Tkinter] Loading Images to Tkinter with Pillow Tomli 2 13,165 Jun-18-2020, 03:26 AM
Last Post: Tomli
  [Tkinter] Problems to display Web Scraping values in Tkinter Lucas_Ribeiro 0 1,592 May-07-2020, 12:36 AM
Last Post: Lucas_Ribeiro
  Images in tkinter menator01 0 1,639 Apr-25-2020, 12:49 AM
Last Post: menator01
  Pillow juuls04 4 3,366 Dec-30-2019, 04:55 AM
Last Post: joe_momma
  Exiting/killing a program with tkinter but leaving the graphic on the screen jpezz 3 4,043 Apr-07-2019, 02:13 PM
Last Post: jpezz
  [Tkinter] Help with tkinter; images and button commands SheeppOSU 2 3,035 Mar-28-2019, 02:01 AM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020