Two Tkinter questions (long)

Tim Hochberg tim.hochberg at ieee.org
Wed Jul 5 19:11:22 EDT 2000


"Aaron Ginn" <aaron.ginn at motorola.com> wrote in message
news:sn66qkgrfv.fsf at motorola.com...
>
> I have two questions about Tkinter.  First, how do you supress a
> command that is executed by a button when a widget is created?  I'm
> trying to create a file browser with three buttons, an OK button which
> applies the selection, a filter button which filters the current
> directory for a matching pattern and a cancel button which does the
> obvious.  The problem is that when I create the file browser in a
> toplevel widget, the command that my buttons are supposed to execute
> are executed immediately.  For instance, here's a portion of code:

[SNIP]

> self.Filter = Button(self.button_frame, text = 'Filter', \
>       command = self.do_filter())

Changing this to:

self.Filter = Button(self.button_frame, text = 'Filter', # Backslash is not
nesc. here.
       command = self.do_filter) # Note no ()

should go a long way toward fixing your problem. What you were doing was
setting command to the result of a call of the function do_filter which
returnd None. Thus the function is executed once when this line is first
executed, but then never again since it is not bound to command, None is.

[SNIP]


-tim





More information about the Python-list mailing list