I'm trying to give the user a set of choices using radio buttons. When I click on the "Get Data Type" button, Python returns "AttributeError: Radiobutton instance has no attribute 'variable'. Clearly it does, but refuses to see it (them):
class DataType:
def __init__(self, master):
frame = LabelFrame(master, text = 'Data Type')
frame.pack()
data_contents = StringVar()
self.radiobutton = Radiobutton(frame,
text="Fixed Data",
variable = data_contents,
value = 'fixed')
self.radiobutton.pack()
self.radiobutton = Radiobutton(frame,
text="Random Data",
variable = data_contents,
value = 'random')
self.radiobutton.pack()
self.radiobutton = Radiobutton(frame,
text="All 1's",
variable = data_contents,
value = '1s')
self.radiobutton.pack()
self.radiobutton = Radiobutton(frame,
text="All 0's",
variable = data_contents,
value = '0s')
self.radiobutton.pack()
data_contents.set(self.radiobutton)
self.printdata = Button(frame,
text="What data?",
command=self.write_data)
self.printdata.pack()
def write_data(self):
print (self.radiobutton.variable)