Re: Simple TK Question - refreshing the canvas when not in focus



On Wed, 30 Apr 2008 10:58:06 +0200, Robert.Spilleboudt <robert.spilleboudt.no.sp.am@xxxxxxxxx> wrote:

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

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+-'])"
.



Relevant Pages

  • Re: Questions about drawing on Canvas
    ... I am attempting for the first time to do some drawing on a canvas. ... Why do you subclass from JPanel to draw rectangles, ... // TODO Find out what effect removing these LOC will have. ...
    (comp.lang.java.programmer)
  • Re: Questions about drawing on Canvas
    ... axes and then superimpose a line on the canvas as well, ... Why do you subclass from JPanel to draw rectangles, ... // TODO Find out what effect removing these LOC will have. ...
    (comp.lang.java.programmer)
  • Re: Newbie looking for info on basic graphics with Delphi.
    ... panel objuct on the main form. ... some of them draw on their parent's canvas. ... I think all of Windows' ...
    (comp.lang.pascal.delphi.misc)
  • Re: Newbie looking for info on basic graphics with Delphi.
    ... Do I need to use a canvas to draw? ... Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ...
    (comp.lang.pascal.delphi.misc)
  • Re: Canvas tp display audio waveform
    ... > I've had limited success displaying the audio waveform of a 16 bit ... > simple and I don't know how to draw points and connect them with lines. ... > In a window with a pushbutton, a listbox and a canvas on it I use this ... Do you have some reason to believe that a WAV file is ...
    (comp.lang.basic.realbasic)