Reputation: 1307
Here I'm trying to select a value using the button. How do I return the value of 'option' from the class? Thanks
I would like to have something like my_gui_value=option_box(root).option Thanks
from Tkinter import Tk, Label, Button
class option_box:
def __init__(self, master):
self.master = master
master.title("A simple GUI")
self.label = Label(master, text="This is our first GUI!")
self.label.pack()
self.train_button = Button(master,text="Training",command=self.train)
self.train_button.pack()
self.test_button = Button(master, text="Testing", command=self.test)
self.test_button.pack()
def train(self):
option=0
print option
def test(self):
option=1
print option
root = Tk()
my_gui = option_box(root)
root.mainloop()
Upvotes: 0
Views: 85
Reputation: 49320
Save it instead of returning it.
def train(self):
self.option = 0
print self.option
def test(self):
self.option = 1
print self.option
Upvotes: 1