You have to make the following changes to your code:
- You have to refer to the function named
activator
as self.activator
when giving it to the Button
(button_2
) as command
.
- You have to change the
parameter
named button
of the function named activator
to self
.
- And the most important thing you need to do is move the part of code where you are placing the
Button
(button_2
) and the Checkbutton
(label_5
), to a new line. Like I have done in the code below. The reason for doing so is that pack
, grid
and place
always return
None
. And when you do it in the same line where you have created your widgets and assigned them to a variable i.e. button_2
and label_5
, the value None
gets stored in that widget.
Here's the corrected code:
import tkinter as tk
class Test:
def __init__(self):
self.master = tk.Tk()
self.master.geometry('550x550')
self.label_5 = tk.Checkbutton(self.master, text="I agree to the", bg='white', width=14, font=("Arial", 8),
command=self.activator)
self.label_5.place(x=112, y=410)
self.button_2 = tk.Button(text='Proceed', width=20, bg='white', state=tk.DISABLED, bd=1,
highlightbackground='black', font=("Arial", 10))
self.button_2.place(x=208, y=512)
self.master.mainloop()
def activator(self):
if self.button_2['state'] == tk.DISABLED:
self.button_2['state'] = tk.NORMAL
else:
self.button_2['state'] = tk.DISABLED
if __name__ == '__main__':
Test()