Python Forum
[Tkinter] Loading Images to Tkinter with Pillow
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Loading Images to Tkinter with Pillow
#3
(Jun-18-2020, 03:03 AM)deanhystad Wrote: This program fails too:
from tkinter import *

image = PhotoImage(file='image.png')
The error is
Output:
Traceback (most recent call last): File "C:\Users\djhys\Documents\python\musings\junk.py", line 3, in <module> image = PhotoImage(file='image.png') File "C:\Program Files\Python38\lib\tkinter\__init__.py", line 4061, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "C:\Program Files\Python38\lib\tkinter\__init__.py", line 3994, in __init__ raise RuntimeError('Too early to create image') RuntimeError: Too early to create image
This program runs
from tkinter import *

Tk()
image = PhotoImage(file='image.png')

deanhystad THANK YOU!
You're totally right, to use the PhotoImage method I have to call it inside the Tk() loop and now that I did that my code is working!
Again thank you!
Reply


Messages In This Thread
Loading Images to Tkinter with Pillow - by Tomli - Jun-17-2020, 04:02 AM
RE: Loading Images to Tkinter with Pillow - by Tomli - Jun-18-2020, 03:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems trying to position images with Tkinter emont 3 843 Dec-12-2023, 07:20 AM
Last Post: menator01
  Images in tkinter menator01 0 1,630 Apr-25-2020, 12:49 AM
Last Post: menator01
  Pillow juuls04 4 3,335 Dec-30-2019, 04:55 AM
Last Post: joe_momma
  tkInter and Pillow don't display any images in GUIs - program gives errors instead SomeRandomGuy 9 10,951 Oct-29-2019, 02:57 PM
Last Post: SomeRandomGuy
  [Tkinter] Help with tkinter; images and button commands SheeppOSU 2 3,021 Mar-28-2019, 02:01 AM
Last Post: woooee
  Remove duplicate images - tkinter? darter 5 5,418 Nov-10-2018, 10:54 PM
Last Post: Larz60+
  Tkinter widgets not fully loading nortski 3 3,566 Apr-02-2018, 12:23 PM
Last Post: nortski

Forum Jump:

User Panel Messages

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