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

Michael Lange klappnase at web.de
Sun Aug 15 13:55:47 CEST 2010


Hi Chris,

On Fri, 13 Aug 2010 20:19:26 +1000
chris chia <hyperila at hotmail.com> 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.

I hope this helps

Michael



More information about the Tkinter-discuss mailing list