r_value= StringVar()
r_value.set("R <= 10k")
def less10k():
enrvalue0 = Vp/0.001 #enr formula for 1 mA
return enrvalue0
Radiobutton(in_frame, text="Resistance Less than or Equal to 10k",variable=r_value, value="R <= 10k",font=24,command=less10k).grid(row=0,column=1,sticky="W")
def great10k():
enrvalue1 = Vp/0.0001 #enr formula for 0.1 mA
return enrvalue1
Radiobutton(in_frame, text="Resistance Greater than 10k", variable=r_value, value="R > 10k",font=24,command=great10k).grid(row=1,column=1,sticky="W")
pot=r_value.get()
if pot=="R <= 10k":
enrvalue=less10k()
print(0)
else:
enrvalue=great10k()
print(1)
if enrvalue<100:
result =Label(out_frame, text="PASS", fg="white", bg="green", font=108,width=10,height=5).grid(row=0,column=4,rowspan=4)
else:
result =Label(out_frame, text="FAIL", fg="white", bg="red", font=108,width=10,height=5).grid(row=0,column=4, rowspan=4)
I want that if I select 'R <= 10' it should select formula for 'enrvalue=Vp/0.001' and if I change to 'R > 10k' it should select 'enrvalue=Vp/0.0001'. and also i want 'enrvalue' further to compare it by ideal value(100). i want to know how can i change the value of 'pot' it always stick to my preset value of 'R <= 10k'.
CodePudding user response:
You can specify a default when you declare the r_value. The specific formula is run after the command triggers the function.
import tkinter as tk
root = tk.Tk()
Vp = 0.09
r_value = tk.StringVar(None, "R <= 10k")
root.result = tk.Label(root, fg='white', width=10, height=5)
root.result.grid(row=2)
def compare_10k():
if r_value.get() == "R <= 10k":
print(0)
enrvalue = Vp / 0.001 # enr formula for 1 mA
else:
print(1)
enrvalue = Vp / 0.0001 # enr formula for 0.1 mA
if enrvalue < 100:
root.result.configure(bg="green", text="PASS")
else:
root.result.configure(bg="red", text="FAIL")
tk.Radiobutton(root, text="Resistance Less than or Equal to 10k",
variable=r_value,
value="R <= 10k",
font=24,
command=compare_10k).grid(row=0, sticky="W")
tk.Radiobutton(root, text="Resistance Greater than 10k",
variable=r_value,
value="R > 10k",
font=24,
command=compare_10k).grid(row=1, sticky="W")
compare_10k()
root.mainloop()