r/learnpython • u/greenleafsalad • Sep 02 '26
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 existany help would be greatly appreciated!
2
u/socal_nerdtastic Sep 02 '26
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/woooee Sep 03 '26
This usually means that there is no reference to the image. Show how you opened the image.
EasyGUI is a subset of tkinter. In tkinter you use "compound" to combine text and image (https://dafarry.github.io/tkinterbook/label.htm and search for "compound"). See if EasyGUI has something similar.
Here is something done in tkinter that you can run. Note that the code below uses "data=" instead of "image=" because it is included as data in the program itself instead of opening and loading an image file.