Recently got stuck on a part of my code which doesn't seem to make much sense to me. I'm busy with a program with multiple Screens to monitor a water process. In a Setup Page, There are radio button options To select the amount of Filters (1-4) alongside other settings. To Group These radio button Filter_Num = tk.IntVar()
is used and then the value is assigned by 4 Radio Buttons.
Filt1=tk.Radiobutton(self, text = "1" ,variable=Filter_Num,value=1)
Filt1.place(x=700,y=141)
Filt2=tk.Radiobutton(self, text = "2" ,variable=Filter_Num,value=2)
Filt2.place(x=750,y=141)
Filt3=tk.Radiobutton(self, text = "3" ,variable=Filter_Num,value=3)
Filt3.place(x=700,y=160)
Filt4=tk.Radiobutton(self, text = "4" ,variable=Filter_Num,value=4)
Filt4.place(x=750,y=160)
Now using this on another page where the control options are shown i have a function that shows the statussus of the outputs, this updates every 500 milliseconds, black being it is disabled, but when using a comparison operator as such
if Filter_Num < 4:
self.Filter4Can.itemconfigure(self.Filter_4i, fill="black")
elif (Filter_4_Solenoid == 1) and (Filter_Num >= 4):
self.Filter4Can.itemconfigure(self.Filter_4i, fill="green")
else:
self.Filter4Can.itemconfigure(self.Filter_4i, fill="red")
the program runs the error "TypeError: '<' not supported between instances of 'IntVar' and 'int'"
Understandable, so I need to use .get() or .getvar() to retrieve the value inside the Variable, as such self.Filter_Number = Filter_Num.get()
, but if do that I get the error "AttributeError:'int' object has no attribute 'get'"
If i understand this correctly, Its either telling me its an IntVar and cant compare, or telling me its an Integer and cant get the Value from it. Am I missing something? I'm fairly new to the language.
Whats Even More Strange is when Using the IntVar within an if as such
if Filter_4_Solenoid == 1:
x = Filter_Num
x = x.get()
print(x)
The Value is converted without Problem and I can get 1 - 4, But Outside the If, the Problem Persists