Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tkinter: spinbox command and percent substitutions

Reply
Thread Tools

Tkinter: spinbox command and percent substitutions

 
 
Tony Eva
Guest
Posts: n/a
 
      11-08-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


 
Reply With Quote
 
 
 
 
Jeff Epler
Guest
Posts: n/a
 
      11-09-2003
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ttk.Spinbox missing? Mark Summerfield Python 0 06-06-2012 01:06 PM
spinbox bombs Bill Welch Ruby 4 01-20-2006 09:20 PM
Spinbox - TCL/Tk 8.4 - Ruby 1.8.2 Bill Welch Ruby 0 01-20-2006 04:07 PM
[command processing -e] perform substitutions listed in a file on a path Hike Mike Perl Misc 2 07-22-2005 04:59 PM
Spinbox (Tkinter module) Askari Python 0 04-04-2004 12:02 AM



Advertisments