Note that there are some explanatory texts on larger screens.

plurals
  1. PORunning a Tkinter form in a separate thread
    primarykey
    data
    text
    <p>I have written a short module that can be passed an image and simply creates a Tkinter window and displays it. The problem that I am having is that even when I instantiate and call the method that displays the image in a separate thread, the main program will not continue until the Tkinter window is closed.</p> <p>Here is my module:</p> <pre><code>import Image, ImageTk import Tkinter class Viewer(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent = parent self.initialize() def initialize(self): self.grid() def show(self,img): self.to_display = ImageTk.PhotoImage(img) self.label_image = Tkinter.Label(self,image=self.to_display) self.label_image.grid(column = 0, row = 0, sticky = "NSEW") self.mainloop() </code></pre> <p>It seems to work fine, except when I call it from my test program like the one below, it will not seem to allow my test program to continue, even when started in a different thread.</p> <pre><code>import Image from viewer import Viewer import threading def showimage(im): view = Viewer(None) view.show(im) if __name__ == "__main__": im = Image.open("gaben.jpg") t = threading.Thread(showimage(im)) t.start() print "Program keeps going..." </code></pre> <p>I think that perhaps my problem is that I should be creating a new thread within the module itself, but I was wanting to just try and keep it simple, as I am new to Python.</p> <p>Anyway, thanks in advance for any assistance.</p> <p>edit: To clarity, I am just trying to make a module that will display an image in a Tkinter window, so that I can use this module any time I want to display an image. The problem that I am having is that any time a program uses this module, it cannot resume until the Tkinter window is closed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload