Tkinter event question

Eric Brunel eric.brunel at pragmadev.N0SP4M.com
Tue Nov 4 04:29:55 EST 2003


Russell E. Owen wrote:
> 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>>")

Do you really need to send the event to the label itself here? Apparently, it is 
what causes the problem: doing a self.master.event_generate("<<Foo>>") has the 
expected result.

Anyway, this is more a tcl/tk bug than a Python/Tkinter bug. If you know enough 
tcl, you may try to report the problem to comp.lang.tcl.

HTH
-- 
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com





More information about the Python-list mailing list