For an BooleanVar() so we can check the different modes of this variable, like this
r :Read - the variable is read by someone w :Write- the variable is written by someone. u :undefined – The variable is deleted
Here is an example which uses w ( write ) mode to display the value of the variable when ever it changes.
We used one Button and used on Click event to change the value of this variable bv1 from False to True.
In above examples we used set() method to assign data to the Boolean variable and to read the data stored we used get() method. These two methods are frequently used in our scripts.
bv1.set(1) # assign value to bv1
print(bv1.get()) # display the value assigned to bv1
Initializing BooleanVar
We can using set() method to assign data to BooleanVar, after declaring or we can assign value while declaring the string variable.
bv1=tk.BooleanVar(value=True) # Assign value to bv1
Length of BooleanVar
Before using len function, we have to convert the BooleanVar to string by using str()
print(len(str(bv1.get()))) # 4
Normal Variable and BooleanVar
BooleanVar() is a class in Tkinter. In a GUI application we require various events to be captured to trigger different functions (requirements). If we use normal Python variable with widgets then monitoring the changes is difficult. However by using a BooleanVar we can monitor the changes and trigger functions based on the requirements.