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. Advertisements

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. Harlin Seritt
    Replies:
    8
    Views:
    640
    tiissa
    Apr 28, 2005
  2. Kevin Walzer
    Replies:
    2
    Views:
    1,351
    Hendrik van Rooyen
    Nov 20, 2006
  3. Johan Lans
    Replies:
    2
    Views:
    1,016
    eb303
    May 31, 2010
  4. thunk
    Replies:
    1
    Views:
    564
    thunk
    Mar 30, 2010
  5. thunk
    Replies:
    0
    Views:
    724
    thunk
    Apr 1, 2010
  6. thunk
    Replies:
    14
    Views:
    884
    thunk
    Apr 3, 2010
  7. Frederic Rentsch
    Replies:
    0
    Views:
    418
    Frederic Rentsch
    Jul 8, 2012
  8. Terry Reedy
    Replies:
    15
    Views:
    912
    Frederic Rentsch
    Jul 16, 2012
Loading...