Python - Tkinter CheckButton Issue
This is a part of my GUI program that I'm having a problem with and hoping someone could help me. What I'm trying to do is, when you click the check button, it should show the pric
Solution 1:
You're overwriting the boolean variable with the checkbox itself. The declaration of your BoolenaVar
needs a different name, and your other function needs to check that name.
Also, checkboxes use 0 and 1 by default to describe their state. If you want to use a boolean you need to change onvalue
and offvalue
accordingly.
def matinee_pricing(self):
# [...]
self.matinee_price_var = BooleanVar() # Different name for the variable.
self.matinee_price = tkinter.Checkbutton(text = '101 \nthru \n105', font=('Verdana', 10), bg='light pink', height=5, width=10,\
variable = self.matinee_price_var, onvalue=True, offvalue=False, command = self.update_text)
# Add onvalue, offvalue to explicitly set boolean states.
# [...]
def update_text(self):
price = ''
# Use the variable, not the checkbox
if self.matinee_price_var.get():
price += '$50'
#[...]
P.S.: You don't need the \ to break lines inside a bracket. Python assumes everything inside the brackets is part of the preceeding command, in this case the checkbox. Just make sure you're not getting any syntax errors and don't split individual arguments across lines.
Post a Comment for "Python - Tkinter CheckButton Issue"