Tkinter: spinbox command and percent substitutions

Discussion in 'Python' started by Tony Eva, Nov 8, 2003.

  1. Tony Eva

    Tony Eva Guest

    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
     
    Tony Eva, Nov 8, 2003
    #1
    1. Advertising

  2. Tony Eva

    Jeff Epler Guest

    You'll have to arrange for the Tk -command to contain %x and %y
    substitutions, and similarly for the -validatecommand.

    The sequence would look something like this:
    tkcmd = self.register(self.sbcmd)
    self.sb = Tkinter.Spinbox(self, command=(tkcmd, "%x", "%y"))
    ...
    def sbcmd(self, x, y):
    print x, y
    I don't have 8.4, so I can't test this out exactly.

    Jeff
     
    Jeff Epler, Nov 9, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Askari

    Spinbox (Tkinter module)

    Askari, Apr 4, 2004, in forum: Python
    Replies:
    0
    Views:
    687
    Askari
    Apr 4, 2004
  2. Bill Welch

    spinbox bombs

    Bill Welch, Jan 19, 2006, in forum: Ruby
    Replies:
    4
    Views:
    156
    Gerald Murray
    Jan 20, 2006
  3. Bill Welch

    Spinbox - TCL/Tk 8.4 - Ruby 1.8.2

    Bill Welch, Jan 20, 2006, in forum: Ruby
    Replies:
    0
    Views:
    130
    Bill Welch
    Jan 20, 2006
  4. Hike Mike
    Replies:
    2
    Views:
    104
    James Taylor
    Jul 22, 2005
  5. Mark Summerfield

    ttk.Spinbox missing?

    Mark Summerfield, Jun 6, 2012, in forum: Python
    Replies:
    0
    Views:
    325
    Mark Summerfield
    Jun 6, 2012
Loading...

Share This Page