By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Some snippets of the involved routines:

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

self.active_fr = start
self.size = size
self.choice = choice
self.choice = IntVar(value=start)


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

def display(self, fr):
self.frames[fr].pack(fill=BOTH, expand=1)
self.active_fr = fr
Nov 29 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.