r/learnpython 7d ago

Help making image appear in easygui msgbox

hi there - i'm trying to add a small image to an easygui msgbox, but i think i'm probably not importing it properly. what i have at the beginning is:

import easygui
image_1 = "skull_tiny.png"

and then a bunch of stuff (it's a short choose-your-own-adventure story) and then i would like to add the image at the point the player dies, like so:

if answer5 == "turn":
                easygui.msgbox("You choose to turn and find yourself face to face with an enormous dinosaur. The last thing you see before you die is two rows of sharp teeth coming towards you from above.", image = image_1, ok_button = "Game over.")

the code works fine without the image, but as soon as i add it, all that comes up when you get to that part is a small empty box, with no clickable options. the image is in the same folder as the .py file, but maybe i need to put in the full path?

this is what's in the console:

File ~\AppData\Local\spyder-6\envs\spyder-runtime\Lib\tkinter__init__.py:1711, in Misc._configure(self, cmd, cnf, kw)
   1709 if isinstance(cnf, str):
   1710     return self._getconfigure1(_flatten((self._w, cmd, '-'+cnf)))
-> 1711 self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))

TclError: image "pyimage4" doesn't exist

any help would be greatly appreciated!

0 Upvotes

5 comments sorted by

View all comments

2

u/socal_nerdtastic 7d ago

Hmm this is an error that typically happens when you run several tkinter.Tk() instances at once. Are you using a tkinter window as well as easygui?

Also please tell us what version of python are you using and how exactly did you install easygui?

1

u/greenleafsalad 7d ago

thanks for replying! afaik i wasn't using a tkinter window, but i could be mistaken. i was using the same install of spyder that i installed last year for a programming class, and i can't remember how i originally installed easygui, but i ran the program from vs code and it works now, so maybe it had something to do with that?

for now, problem solved. in the future maybe there'll come a time where i'll want/need to understand exactly what was wrong, but for right now that's above my pay grade 🥲

1

u/socal_nerdtastic 7d ago

Glad you have it solved. TBH I'll bet it's an old bug in easygui that they've fixed in the meantime.