Tkinter: spinbox command and percent substitutions

Tony Eva tonyeva at talk21.net
Sat Nov 8 17:32:33 EST 2003


The spinbox widget in Tk 8.4 has an option to allow a command
to be specified that is invoked when either the up or down buttons
of the spinbox are pressed, as in:

  ...
  self.sb = Tkinter.Spinbox( self, command = self.sbcmd )
  ...

  def sbcmd( self, *args ):
      print args

However, it seems that no parameters are passed to the command (the
print statement outputs "()"), and so it is not possible to tell
which button was pressed to invoke the command.  The Tk man pages
say that the "%d" substitution will be either "up" or "down", but
I cannot see how to get at these substitutions.

The same applies to other command options, e.g. validatecommand,
where the Tk man page implies that percent substitutions are used
to pass info into the command.  How does one do this?

I'd like to use the command option to implement a spinbox to select
from a large range of values that are not regular (so the 'to', 'from',
'step' and 'value' options can't be used or are very clunky.)

Can anyone help?  (This is Python 2.3, Windows install, if it's
relevant.)

-- 
Tony






More information about the Python-list mailing list