On Tue, 29 Apr 2008 15:22:12 +0200, blaine <[EMAIL PROTECTED]> 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()

Unrelated question: why are you doing a .pack() again here? Packing the widget just inserts it at the right place in its container, so you only have to do it once. So the one you did in __init__ is enough.

I've tried self.root.set_focus(), self.root.force_focus(),
self.canvas.update(), etc. but I can't get it.

IIRC:
- self.root.set_focus() will only work if your application already has the focus, so it's not what you need here. - self.root.force_focus() is usually considered as evil: it'll give the focus to your application whatever the user is doing, which is usually *really* annoying. So I guess a lot of window managers just refuse to do it; this may be what happens here.

But self.canvas.update() should work. If it doesn't, then there are probably limitations on your platform that prevents it to work... Do you happen to have other applications that can update their display while they don't have the focus? Do they have the same problem? If they do, it's probably a limitation on the platform and I guess you won't be able to do anything about it... BTW, what platform are you on?

Thanks!
Blaine

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to