I have used the line of code below to input a variable for “BAI_var1” in a multiple choice command line software.
BAI_var1 = input ("Please enter 0 for not at all, 1 for somewhat, 2 for moderatly or 3 for a lot:")
Here is my Graphic User Interface:
from Tkinter import *
import time
class App:
def __init__(self, master):
w = Label(master, text="1. Anxiety, nervousness, worry or fear")
w.pack()
v = IntVar()
Radiobutton(master, text="0 for not at all", variable=v, value=1).pack(side=TOP, anchor="w")
Radiobutton(master, text="1 for somewhat", variable=v, value=2).pack(side=TOP, anchor="w")
Radiobutton(master, text="2 for moderatly", variable=v, value=3).pack(side=TOP, anchor="w")
Radiobutton(master, text="3 for a lot", variable=v, value=4).pack(side=TOP, anchor="w")
self.button = Button(master, text="BACK", fg="red", command=self.button6)
self.button.pack(side=BOTTOM)
self.button = Button(master, text="NEXT", fg="red", command=self.button5)
self.button.pack(side=BOTTOM)
def button6(self):
print "Sam is awesome!GAJONGA"
def button5(self):
print "PYTHON FOR THE WIN! GIAN SAYS PYTHON = FILTHY"
master = Tk()
app = App(master)
master.mainloop()
My problem is that I don’t know how to use a Radiobutton to input a set integer to a variable.
Use a dictionary to map the integer values to the strings they represent:
You can then use this to create the UI:
When you need to fetch the values, obviously it’s just a simple dictionary lookup using the value of the variable as the key.