У меня есть этот код, который просит пользователя выбрать один из вариантов. Я использовал радиопульты. После того, как пользователь выберет свой выбор, на выбор будет использован другой оператор if. Я уже назначил переменную выбора как variable = specialistchoose
. Но когда я использую specialistchoose
или specialistchoose.get()
, он не работает. Может ли кто-нибудь помочь?Назначить переменную радиоблоку Tkinter
specialistchoose = IntVar()
r1 = Radiobutton (f2, text = "Cardiology", variable = specialistchoose, value = 1, command = command_r1)
r1.grid(row = 4, column = 0, stick = W)
r2 = Radiobutton (f2, text = "Gastroenterology", variable = specialistchoose, value = 2, command = command_r2)
r2.grid(row = 4, column = 1,stick = W)
r3 = Radiobutton (f2, text = "Dermatology", variable = specialistchoose, value = 3, command = command_r3)
r3.grid (row = 4, column = 2,stick = W)
r4 = Radiobutton (f2, text = "Psychiatry", variable = specialistchoose, value = 4, command = command_r4)
r4.grid (row = 5, column = 0,stick = W)
r5 = Radiobutton (f2, text = "Dentist", variable = specialistchoose, value = 5, command = command_r5)
r5.grid(row = 5, column = 1,stick = W )
f2.place(relx = 0.01, rely = 0.125, anchor = NW)
Label(f1, text = "Specialist").place(relx = .06, rely = 0.125, anchor = W)
f1.grid(stick = W)
if specialistchoose.get() == "Cardiology":
file = open ("test2.txt", "w")
file.write ("Specialist : Cardiology")
file.close()
elif specialistchoose.get() == "Gastroenterology":
file = open ("test2.txt", "w")
file.write ("Specialist : Gastroenterology")
file.close()
elif specialistchoose.get() == "Dermatology":
file = open ("test2.txt", "w")
file.write ("Specialist : Dermatology")
file.close()
elif specialistchoose.get() == "Psychiatry":
file = open ("test2.txt", "w")
file.write("Specialist : Psychiatry")
file.close()
elif specialistchoose.get() == "Dentist":
file = open ("test2.txt", "w")
file.write("Specialist : Dentist")
file.close()
примечание: это всего лишь образец более длинного кода.