Does changing a Tkinter Variable bound to a widget invoke its'command' callback function?

Discussion in 'Python' started by execrable@gmail.com, Nov 29, 2007.

  1. Guest

    I am writing a simple (maybe a bit conveluded, but I just started
    learning Tkinter) program that uses a 'notebook' code snippet from a
    python cookbook. It creates a customizable frame and radio button for
    each 'tab' and uses .forget to hide the frames that aren't 'current'.
    I modified it to use a Scale slider bar instead of radio buttons.

    What my program does is create a parent notebook object, and in each
    notebook frame, child notebooks are created. All the sliders are
    created with:

    command=lambda x: self.display(int(x))

    Which displays the contents of the associated notebook frame (via
    forget/pack). All of this also works fine, but I wanted it to be a
    little more user-friendly by linking all the sliders on the child
    notebooks using a control IntVar so that each child notebook can be on
    the same page while scrolling through them. The problem is that when
    the currently displayed slider is moved, it updates the current child
    notebook, but not the notebooks of the hidden frames. Their sliders
    are moved when they are next displayed, but the associated frames are
    not updated, so there is a mismatch between slider and frame until
    that specific slider is moved.

    I can't find much information on control variables with respect to
    Scale widgets, so any insight, hints, or suggestions would be greatly
    appreciated.

    Some snippets of the involved routines:

    def __init__(self, master, size, start=0, side=LEFT, choice=None):

    self.active_fr = start
    self.size = size
    if(choice):
    self.choice = choice
    else:
    self.choice = IntVar(value=start)

    ....

    # create slider
    self.slide = Scale(self.rb_fr, variable=self.choice,
    orient=self.orient,
    from_=start, to=(size-start+1), length=200,
    command=lambda x: self.display(int(x)))
    ....

    def display(self, fr):
    self.frames[self.active_fr].forget()
    self.frames[fr].pack(fill=BOTH, expand=1)
    self.active_fr = fr
     
    , Nov 29, 2007
    #1
    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. Jeff Epler
    Replies:
    0
    Views:
    533
    Jeff Epler
    Aug 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    481
    Jeff Epler
    Aug 23, 2004
  3. Frederic Rentsch
    Replies:
    0
    Views:
    275
    Frederic Rentsch
    Jul 8, 2012
  4. Terry Reedy
    Replies:
    15
    Views:
    673
    Frederic Rentsch
    Jul 16, 2012
  5. Frederic Rentsch
    Replies:
    0
    Views:
    463
    Frederic Rentsch
    Jul 9, 2012
Loading...

Share This Page