Hi,

OS is Linux,

Python version is 3.6.5

I am trying to change the command of a tkinter Button in my program. Eventually I want to be able to do this to many buttons.

My attempt at code brings up no error messages, but the button appears to do nothing.

I really have no idea how to do this, but this is what I wrote.

====================================

#!/usr/bin/python3
from tkinter import *

class form(object):
    def __init__(self, x, reply, master, z,bu):
        self.x=x
        self.reply=reply
        self.master=master
        self.z=z
        self.bu=bu

    def change(x, reply, z, b):
        #f contains the alternative command (as a string)
        f=["lambda x=vars, txt=reply,fu=0 bu=b1 :form.change(x, txt, fu, bu)", "lambda x=vars, txt=first, fu=1 bu=b1: form.change(x, txt, fu, bu)"]
        for i in range(4):
            x[i].set(reply[i])
        #attempt to change command clause
        set.button(f[z])

    def draw(master):
        vars = []
        label = []
        button = StringVar
        for i in range(4):
            var = StringVar()
            vars.append(var)
            label.append("")
            label[i] = Label( master, textvariable=var, relief=RAISED ).grid(row=i, column=0)
            vars[i].set(first[i])
        b1=Button(master, text="change", command=button).grid(row=i+1, column=0)


reply=["now I don't know", "Happy birthday", "Many happy returns", "Next it's my turn",1] first=["What's your name?", "My name is Fred", "I have just had my birthday", "your's is next!",2]
master=Tk()

form.draw(master)
master.mainloop()

=================================

How should I do this, I had worked around the problem by destroying  the window and building it again, but it was pointed out that I have an unusual coding style doing this.

All hints appreciated!

Regards, Chris Roy-Smith

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to