0

My question is for example i have 3 buttons (bt1,bt2,bt3). How can i simultaneously change their state without calling them by their proper names, using btn[i] or something?

1
  • 3
    why not put them in a list and iterate over? Commented Oct 25, 2014 at 21:44

1 Answer 1

2

You can use a for loop like this, which just takes all buttons and disables them in an easy to write way:

for x in (btn1, btn2, btn3):
    x.config(state = 'disabled')

I think this does what you want it to?

here is a full example:

import tkinter as tk
r = tk.Tk()

def disable_all():
    d.destroy()
    for z in (a, b, c):
        z.config(state = 'disabled')

def func(y):
    print('you clicked button ', y)

a = tk.Button(text = 'A', command = lambda: func('a'))
b = tk.Button(text = 'B', command = lambda: func('b'))
c = tk.Button(text = 'C', command = lambda: func('c'))
d = tk.Button(text = 'disable all', command = disable_all)

for x in (a, b, c, d):
    x.pack()

r.mainloop()

hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.