471,580 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,580 software developers and data experts.

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

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 '07 #1
0 1023

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by fb | last post: by
4 posts views Thread by arvind | last post: by
5 posts views Thread by archana | last post: by
1 post views Thread by Horace Nunley | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.