[Tkinter-discuss] Continued: force the GUI to switch image instead of relying on the <button-1> event

Cameron Laird Cameron at phaseit.net
Sun Aug 15 19:26:12 CEST 2010

On Sun, Aug 15, 2010 at 01:55:47PM +0200, Michael Lange wrote:
> > I wish to do a multi threading program such that user can still use
> > the console to control this GUI. Can I ask u how can i write a
> > command to force the GUI to switch image instead of relying on the
> > <button-1> event.
> > 
> I am not sure what you want to achieve; in case you want the user to be
> able to use the keyboard insted of the mouse, you can simply use
> bindings to Key events instead of <Button-1>, like <Control-n> for a
> "next image"-callback and <Control-p> for "previous image". You can even
> apply such bindings to the toplevel window as a whole, so the users
> will not have to set the keyboard focus to a particular widget.
> If you want to control the window from a different application, you can
> try to add a signal handler using Python's signal module (however,
> this may not be supported on all platforms).
> Or do you want the application to automagically switch the image after
> a given amount of time? Then you can use a simple after() loop, like:
>     def switch_image():
>         ImageViewer.change_image()
>         root.after(5000, switch_image)
>     root.after(5000, switch_image)
> In this example the change_image() method of course needs to take care
> that after displaying the last image from the images list it will start
> over again with the first one.
And, in yet another direction, I wonder if the original questioner is
confused about the relation between "multi threading" and GUI 
responsiveness (and concurrency, and so on).  It's possible <URL:
http://wiki.tcl.tk/1526 > will be pertinent.

More information about the Tkinter-discuss mailing list