[Tkinter-discuss] Tkinter - Drawing Webcam Images?

Michael Lange klappnase at web.de
Wed Jun 2 11:23:28 CEST 2010


Hi,

On Tue, 1 Jun 2010 13:43:08 -0700 (PDT)
Krb686 <Krb686 at gmail.com> wrote:

> 
> I'm pretty new to Python and Tkinter, so there might be an easier or
> more advanced way of doing this that I don't know of, but bear with
> me.  I'm making a simple webcam gui using VideoCapture and PIL, and I
> realized that to get the video working you must retrieve and display
> the images in a loop on the gui, but you can't do this normally
> without threading because then the gui won't update any more, or at
> least as far as I know.  So I need some help on this if anyone knows
> an easier way to do this without threading. And is it possible to
> allow your own code to run within the tkinter mainloop? Because then
> I could just allow it to update with the gui mainloop and not use
> threading.

Maybe you could use a loop with after() calls and update_idletasks() to
update the image, like this simple example:

def update_loop():
    update_image()
    somewidget.update_idletasks()
    somewidget.after(100, update_loop)

With a useful update_image() method you just need to enter the loop
once and it should do what you want.

I hope this helps

Michael



More information about the Tkinter-discuss mailing list