Tkinter Query

Newt newt_e at blueyonder.co.uk
Wed Oct 9 18:05:55 EDT 2002


Hi,

I'm trying to build a form with some rows. Each row consists of a down
button, a label, and an up button. When the down button is pressed, I want
the value in the label to go down, and if the up button is pressed then the
value goes up. The code looks like (I haven't done the up button yet, and I
know I'm only changing the value of the label from 10 to 9 (if it
worked...)).

class SelectSkills:
    def __init__( self, parent ):
        pos = 0
        svals = []
        allskills = ['Skill 1','Skilll 2','Skill 3','Skill 4']
        for skill in allskills:
            sval = Label(wskill, text = "10").grid(row=pos+2,col=2)
            dbut_callback = curry( self.down, pos,  parent )
            dbut = Button(wskill, text='<',
command=dbut_callback ).grid(row=pos+2,col=1)
            rbut = Button(wskill, text='>').grid(row=pos+2,col=3)
            svals.append(sval)
            pos = pos + 1

        return

     def down( self, i, *crap):
        global svals
        showinfo('Down','In Down:'+str(i))
        sval = svals(pos)
        sval.configure(text = '9')
        return

In the code above, I'm trying to use svals to hold the values of sval as
they are created.

When I run this, I get an error that svals is not a global. So two
questions:
1. How do I make svals into a global?
2. What is the correct way to implement what I'm trying to do?

Thanks in advance,

Newt





More information about the Python-list mailing list