newbie Tkinter scale question..

Ron Stephens rdsteph at earthlink.net
Tue Apr 10 21:21:33 EDT 2001


I want to make the output of one scale be the input for another scale.
When I try to do this, my program just hangs my computer. I have been
trying to use the scale.get method. as in: (please do not try to run
this for you will have to do a hard reboot if you run windows):: (her I
am trying to print a variable zed = scale.get() which hangs the
computer...I also tried scale1.set(zed) which also hangs the
computer...thanks if anyone can help me...

from Tkinter import *
import string


def setHeight(canvas, heightStr):
    height = string.atoi(heightStr)
    height = height + 21
    y2 = height - 30
    if y2 < 21:
        y2 = 21
    canvas.coords('poly',
15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20)
    canvas.coords('line',
15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20)

root = Tk()
root.option_readfile('optionDB')
root.title('Scale')

canvas = Canvas(root, width=50, height=50, bd=0, highlightthickness=0)
canvas.create_polygon(0,0,1,1,2,2, fill='cadetblue', tags='poly')
canvas.create_line(0,0,1,1,2,2,0,0, fill='black', tags='line')
scale = Scale(root, orient=VERTICAL, length=284, from_=0, to=250,
              tickinterval=50, command=lambda h,
c=canvas:setHeight(c,h))
scale.grid(row=0, column=0, sticky='NE')
canvas.grid(row=0, column=1, sticky='NWSE')
scale.set(100)

zed = scale.get()

root.title('Scale')

canvas1 = Canvas(root, width=50, height=50, bd=0, highlightthickness=0)
canvas1.create_polygon(2,2,1,1,2,2, fill='cadetblue', tags='poly')
canvas1.create_line(2,2,1,1,2,2,0,0, fill='black', tags='line')
scale1 = Scale(root, orient=VERTICAL, length=284, from_=0, to=250,
              tickinterval=50, command=lambda h,
c=canvas:setHeight(c,h))
scale1.grid(row=1, column=1, sticky='NE')
canvas1.grid(row=1, column=2, sticky='NWSE')
scale1.set(100)
zed = scale.get()
print zed
root.mainloop()











More information about the Python-list mailing list