Simple TK Question - refreshing the canvas when not in focus

blaine frikker at gmail.com
Tue Apr 29 09:22:12 EDT 2008


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



More information about the Python-list mailing list