Simple TK Question - refreshing the canvas when not in focus

Robert.Spilleboudt robert.spilleboudt.no.sp.am at skynet.be
Wed Apr 30 04:58:06 EDT 2008


blaine wrote:
> Hey everyone!
>   I'm not very good with Tk, and I am using a very simple canvas to
> draw some pictures (this relates to that nokia screen emulator I had a
> post about a few days ago).
> 
> Anyway, all is well, except one thing.  When I am not in the program,
> and the program receives a draw command (from a FIFO pipe), the canvas
> does not refresh until I click into the program. How do I force it to
> refresh, or force the window to gain focus?  It seems like pretty
> common behavior, but a few things that I've tried have not worked.
> 
> Class screen():
>     def __init__(self):
>         self.root = Tkinter.Tk()
>         self.root.title('Nokia Canvas')
>         self.canvas = Tkinter.Canvas(self.root, width =130,
> height=130)
>         self.canvas.pack()
>         self.root.mainloop()
> 
> Then somewhere a long the line I do:
>             self.canvas.create_line(args[0], args[1], args[2],
> args[3], fill=color)
>             self.canvas.pack()
> 
> I've tried self.root.set_focus(), self.root.force_focus(),
> self.canvas.update(), etc. but I can't get it.
> Thanks!
> Blaine
When you read the pipe,  do you generate an event? Probably not , and Tk 
is event-driven and should never update the canvas if there is no event.
This is how I understand Tk.

I have a Tk program who reads a audio signal (from an RC transmitter) . 
I generate a event every 100 msec , and "process" refresh the canvas.
Starting the sequence:
id = root.after(100,process)  will call "process" after 100 msec
At the end of "process", repeat:
id = root.after(100,process)
Robert



More information about the Python-list mailing list