Bigmon
May 25th, 2011, 01:54 PM
I wonder if someone can help. Iam using Tkinter and in my program, when a checkbutton is ticked it adds 1 to a score, and when it is unchecked, 1 is taken off. This seems to work, as I can see the total change as I check and uncheck. However, I cannot seem to return this value out of the method to use it elsewhere.
def create_check_button(self):
self.radio_button = BooleanVar()
Checkbutton(self,
text = "Check For Natalie",
variable = self.radio_button,
command = self.add_one
).pack()
self.radio_button1 = BooleanVar()
Checkbutton(self,
text = "Check For Graham",
variable = self.radio_button1,
command = self.add_one
).pack(side="bottom")
self.radio_button2 = BooleanVar()
Checkbutton(self,
text = "Check For Cash Spend",
variable = self.radio_button2,
command = self.add_one
).pack()
self.radio_button3 = BooleanVar()
Checkbutton(self,
text = "Check For Bank Statement",
variable = self.radio_button3,
command = self.add_one
).pack()
self.radio_button4 = BooleanVar()
Checkbutton(self,
text = "Check For Credit Card",
variable = self.radio_button4,
command = self.add_one
).pack(side="bottom")
def add_one(self, total=0):
"""this function is passed to Checkbutton
above - hence no () above. Everytime a checkbutton is
true one is added to the score. One is taken off with unchecking.
If the total is zero then a warning box will come up"""
self.total = total
if self.radio_button.get():
self.total+=1
if self.radio_button1.get():
self.total+=1
if self.radio_button2.get():
self.total+=1
if self.radio_button3.get():
self.total+=1
if self.radio_button4.get():
self.total+=1
check_button_total = self.total
print(check_button_total)
return check_button_total
I tried putting total as a global value but when I unchecked the box ,the value did not go down.
Can any experienced programmers help ?
def create_check_button(self):
self.radio_button = BooleanVar()
Checkbutton(self,
text = "Check For Natalie",
variable = self.radio_button,
command = self.add_one
).pack()
self.radio_button1 = BooleanVar()
Checkbutton(self,
text = "Check For Graham",
variable = self.radio_button1,
command = self.add_one
).pack(side="bottom")
self.radio_button2 = BooleanVar()
Checkbutton(self,
text = "Check For Cash Spend",
variable = self.radio_button2,
command = self.add_one
).pack()
self.radio_button3 = BooleanVar()
Checkbutton(self,
text = "Check For Bank Statement",
variable = self.radio_button3,
command = self.add_one
).pack()
self.radio_button4 = BooleanVar()
Checkbutton(self,
text = "Check For Credit Card",
variable = self.radio_button4,
command = self.add_one
).pack(side="bottom")
def add_one(self, total=0):
"""this function is passed to Checkbutton
above - hence no () above. Everytime a checkbutton is
true one is added to the score. One is taken off with unchecking.
If the total is zero then a warning box will come up"""
self.total = total
if self.radio_button.get():
self.total+=1
if self.radio_button1.get():
self.total+=1
if self.radio_button2.get():
self.total+=1
if self.radio_button3.get():
self.total+=1
if self.radio_button4.get():
self.total+=1
check_button_total = self.total
print(check_button_total)
return check_button_total
I tried putting total as a global value but when I unchecked the box ,the value did not go down.
Can any experienced programmers help ?