Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter & Canvas
#4
Not an answer, but a problem:

I was interested, so I set:

img = '/home/pedro/Pictures/aphrodite.jpg'

Trying out the code, I am getting:

Quote:Main().mainloop()
Traceback (most recent call last):
File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode
exec(code, self.locals)
File "<pyshell#20>", line 1, in <module>
File "<pyshell#8>", line 6, in __init__
File "<pyshell#17>", line 6, in __init__
File "/usr/lib/python3.10/tkinter/__init__.py", line 4103, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "/usr/lib/python3.10/tkinter/__init__.py", line 4048, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "/home/pedro/Pictures/aphrodite.jpg"

Maybe 1 image could be corrupt, so I tried 2 other images, no joy!

This works:

from PIL import Image
im = Image.open(img)
im.show()
Any ideas what may be the problem?

Quote:bg = tk.PhotoImage(file=img)
Traceback (most recent call last):
File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode
exec(code, self.locals)
File "<pyshell#28>", line 1, in <module>
File "/usr/lib/python3.10/tkinter/__init__.py", line 4103, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "/usr/lib/python3.10/tkinter/__init__.py", line 4048, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "/home/pedro/Downloads/aphrodite.jpg"
Reply


Messages In This Thread
Tkinter & Canvas - by Peter_Emp1 - Mar-23-2024, 01:11 PM
RE: Tkinter & Canvas - by menator01 - Mar-23-2024, 09:41 PM
RE: Tkinter & Canvas - by deanhystad - Mar-24-2024, 02:42 AM
RE: Tkinter & Canvas - by Peter_Emp1 - Mar-24-2024, 07:13 PM
RE: Tkinter & Canvas - by Pedroski55 - Mar-24-2024, 06:25 PM
RE: Tkinter & Canvas - by deanhystad - Mar-24-2024, 07:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to positon a tkinter canvas Tyrel 3 1,965 Dec-11-2020, 03:05 PM
Last Post: deanhystad
  use classes in tkinter canvas fardin 2 2,667 Jan-06-2019, 04:23 AM
Last Post: fardin

Forum Jump:

User Panel Messages

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