Re: Simple TK Question - refreshing the canvas when not in focus
- From: "Eric Brunel" <see.signature@xxxxxxx>
- Date: Wed, 30 Apr 2008 16:01:53 +0200
On Wed, 30 Apr 2008 10:58:06 +0200, Robert.Spilleboudt <robert.spilleboudt.no.sp.am@xxxxxxxxx> wrote:
blaine wrote:Hey everyone!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.
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
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
Your method actually works and is in fact even clearer: you explicitely give back the control to the main event loop by sending the event. But the call to 'update' should also work, since it also gives back the control to the main event loop, implicitely however. BTW, the pending events *are* treated by a call to update, which can cause some surprises...
--
python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
.
- Follow-Ups:
- References:
- Simple TK Question - refreshing the canvas when not in focus
- From: blaine
- Re: Simple TK Question - refreshing the canvas when not in focus
- From: Robert.Spilleboudt
- Simple TK Question - refreshing the canvas when not in focus
- Prev by Date: Re: Python(2.5) reads an input file FASTER than pure C(Mingw)
- Next by Date: I messed up my wxPython install (Eclipse Configuration Issue)
- Previous by thread: Re: Simple TK Question - refreshing the canvas when not in focus
- Next by thread: Re: Simple TK Question - refreshing the canvas when not in focus
- Index(es):
Relevant Pages
|
|