0

I'm doing my first GUI on Tkinter and I'm having some issues getting more than one button to activate after clicking one.

I have the button Main that's always active by default, and once it's pressed it should activate Button1, Button2, Button3, Button5 and Button6 that are disabled by default. This is my code at the moment.

Function that activates the buttons:

def activateButtons():
    for i in (Button1, Button2, Button3, Button5, Button6):
        i.config(state=ENABLED)

Button that calls the function:

loadDB= tk.Button(
  root,
  width=10,
  text = "Load DB.",
  bg = "black",
  fg = "blue",
  command=lambda:[loadDBF(),activateButtons()]).pack(expand = True)

and the buttons:

Button1 = tk.Button(
  root,
  width= 15,
  text= "Button 1",
  bg="black",
  fg="blue",
  state=DISABLED).pack(expand = True)

Button2 = tk.Button(
  root,
  width= 15,
  text= "Button 2",
  bg="black",
  fg="blue",
  state=DISABLED).pack(expand = True)

Button3 = tk.Button(
  root,
  width= 15,
  text= "Button3",
  bg="black",
  fg="blue",
  state=DISABLED).pack(expand = True)

Button4 = tk.Button(
  root,
  width= 15,
  text= "Button 4",
  bg="black",
  fg="blue",
  state=DISABLED).pack(expand = True)

Button4 = tk.Button(
  root,
  width= 15,
  text= "Button 1",
  bg="black",
  fg="blue",
  state=DISABLED).pack(expand = True)

Button5 = tk.Button(
  root,
  width= 15,
  text= "Button 1",
  bg="black",
  fg="blue",
  state=DISABLED).pack(expand = True)

Button6 = tk.Button(
  root,
  width= 15,
  text= "Button 1",
  bg="black",
  fg="blue",
  state=DISABLED).pack(expand = True)

Any idea on how to get them to activate once I press loadDB?

  • All of your `ButtonX` variables are None - the result of `.pack()`, rather than the Buttons themselves. This should be generating a `'NoneType' object has no attribute 'config'` when you try to activate them - are you not seeing that? – jasonharper May 22 '22 at 03:18
  • How could I correct it? If I remove it they dissapear from the GUI – theJohnLewis May 22 '22 at 03:20
  • Just found a way to do it thanks to this correction, thank you! – theJohnLewis May 22 '22 at 03:22

1 Answers1

0

Replace ENABLED with NORMAL.

def activateButtons():
    for i in (Button1, Button2, Button3, Button5, Button6):
        i.config(state=NORMAL)
Abhinav Mathur
  • 7,791
  • 3
  • 10
  • 24