Tkinter event question

From: Russell E. Owen (no_at_spam.invalid)
Date: 11/04/03


Date: Mon, 03 Nov 2003 17:04:26 -0800

I've found a quirk in Tkinter and am wondering if anyone knows a
workaround. I've got some widgets that generate events. Sometimes the
widgets are not displayed, but they may still want to generate these
events.

The problem is, if a widget has never been displayed, event_generate
appears to be ignored. If I display the widget and then hide it again,
event_generate works fine. But...I've got many widgets that are normally
hidden and don't really want the screen flashing with stuff being
displayed and hidden again right away as the application starts up.

Here is a minimal and unrealistic script that shows the problem. Push
the button to generate a <<Foo>> event. The event is actually only
generated if the label that generates it is shown (you can then hide it
again and the events are still generated). Note that the label *is*
initially gridded, but it's taken hidden again before the window manager
ever actually gets to display it.

Suggestions? This is driving me mad, as such events could be quite
useful for communication if I could only generate them reliably.

-- Russell

#!/usr/local/bin/python
from Tkinter import *
root = Tk()

class myLabel(Label):
    def sendFoo(self):
        self.event_generate("<<Foo>>")

def gotFoo(evt):
    print "Got <<Foo>>"
root.bind("<<Foo>>", gotFoo)

c = myLabel(text="I Am A Label")
b = Button(root, text="Send <<Foo>>", command=c.sendFoo)
c.grid(row=0, column=0)
c.grid_remove()
b.grid(row=1, column=0)

showVar = IntVar()
def showFoo():
    if showVar.get():
        c.grid()
    else:
        c.grid_remove()
showC = Checkbutton(root, text="Show Label",
    variable=showVar, command=showFoo)
showC.grid(row=2, column=0)

root.mainloop()



Relevant Pages

  • Re: glutBitmapCharacter - partial letters
    ... the problem on text strings which are longer than the Widgets width ... problem is that I could only display a full letter or not. ... it seems GLUT has a mirrored y-axis. ... down is positive (GLUT has different Y than openGL) ...
    (comp.graphics.api.opengl)
  • Re: Tkinter event question
    ... I've got some widgets that generate events. ... If I display the widget and then hide it again, ... > from Tkinter import * ... Eric Brunel <eric dot brunel at pragmadev dot com> - ...
    (comp.lang.python)
  • Re: scroll a frame to display several lines of widgets at a time
    ... want separate widgets, all displayed at once, for several hundred records - surely better to just reuse the one set of widgets and have the scrollbar or back-forward buttons change which record is being displayed in the widgets. ... Make sure you've created the frame and perhaps called update_idletasksto give it a chance to size itself before shoving it onto the canvas. ... Simple enough, but there are several hundred records, and I only want to display 5 or 10 at a time. ...
    (comp.lang.python)
  • Moving widgets in Tkinter
    ... I wish to manually move widgets in Tkinter, now I have successfully done it, ... def MoveWindow: ...
    (comp.lang.python)
  • Re: Odd behavior in Python/Tkinter?
    ... you've asked them both to display the same variable. ... Tkinter just does what you've asked it to. ... value in a number of radiobutton widgets. ... But an expression (e.g. string) is NOT a variable. ...
    (comp.lang.python)