-1

I'm trying to make a custom popup to act as an about screen for a program i'm making, however when i try to have another window existing before i call the popup i get a tcl message saying the image doesnt exist. for the record i'm using python 3.3.4

complete extract of my code is:

#!python3

from tkinter import *
import PIL.ImageTk
import os
__version__ = "part number"

class Screen():
    def __init__(self):
        aboutscreen = Tk()
        aboutscreen.title("About")
        aboutscreen.photoimg = PIL.ImageTk.PhotoImage(file="Logo.bmp")
        Label(aboutscreen, image=aboutscreen.photoimg).pack()
        Label(aboutscreen, text = "company name", width = 25, font = ("ariel",16)).pack()
        Label(aboutscreen, text = "program name", width = 30, font = ("ariel",12)).pack()
        Label(aboutscreen, text = "Part Number: " + __version__, width = 30, font = ("ariel",12)).pack()
        Label(aboutscreen, text = "Copyright company name", width = 30, font = ("ariel",12)).pack()
        while 1:
            try: aboutscreen.update() #keep update window updated until destroyed
            except: break #break loop when destroyed


if __name__ == "__main__":
    root = Tk()
    app = Screen()

this code is what gives me the error message:

    line 15, in __init__
    Label(aboutscreen, image=aboutscreen.photoimg).pack()
  File "C:\Python33\lib\tkinter\__init__.py", line 2607, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
  File "C:\Python33\lib\tkinter\__init__.py", line 2086, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage1" doesn't exist

but if i comment out the root = Tk() line it works.

can anyone explain where i'm going wrong?

Thanks

James

James Kent
  • 5,763
  • 26
  • 50

1 Answers1

0

It should work if you go:

app = Screen(root)

and take out the:

aboutscreen = Tk()

The issue is having more than one root, or instance of Tk I think.

EDIT:

Found this on a mailing list:

"Tkinter.Tk() creates a new Tcl interpreter. Are you sure you want that? The standard way to create an additional window is Tkinter.Toplevel().

The PhotoImage is created in the default (first) interpreter and then looked up in the Label's (second) interpreter. At least that's what I would infer from

class Image:
    """Base class for images."""
    _last_id = 0
    def __init__(self, imgtype, name=None, cnf={}, master=None, **kw):
        self.name = None
        if not master:
            master = _default_root
            if not master:
                raise RuntimeError, 'Too early to create image'
        self.tk = master.tk

in the Tkinter source which also makes it plausible that you can avoid the problem by specifying an explicit master

def showPicture(imageFilename):
    root = Tk()
    # ...
    imageObject = PhotoImage(file=imageFilename, master=root)
    # ...

"

chris
  • 4,840
  • 5
  • 35
  • 66
  • does this still leave the parent window in the background? – James Kent Jul 14 '14 at 09:44
  • are you trying to use that extra instance of Tk() as the pop-up window over the top of another one? in certain packages like Wx there is a built in class for a splash screen, which is what yours kind of sounds like its doing – chris Jul 14 '14 at 09:47
  • here is a splash screen using Tk: http://code.activestate.com/recipes/577271-tkinter-splash-screen/ – chris Jul 14 '14 at 09:49
  • its not quite a splash screen as i still wanted it to have a frame and title bar, what i couldn't make sense of was why having either the image or the parent window stopped my function from working, if i commented out the code for either it worked (albeit without either the root or the image) – James Kent Jul 14 '14 at 10:05