The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Tkinter-Checkbutton's variable doesn't change
Discuss Tkinter-Checkbutton's variable doesn't change in the Python Programming forum on Dev Shed. Tkinter-Checkbutton's variable doesn't change Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 18th, 2013, 07:10 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 13
Time spent in forums: 2 h 41 m 27 sec
Reputation Power: 0
|
|
|
Tkinter-Checkbutton's variable doesn't change
Hi everyone..
I have a problem coding in python tkinter.The variable of the checkbutton returns ( is) always 0.So I can't know if the user selects each checkbutton or not.
My code is below:
Code:
from Tkinter import *
class First_Opening():
def __init__(self):
self.first_open_var1=IntVar()
self.first_open_var2=IntVar()
self.list12=[]
top=Tk()
top.title('Program')
top.resizable(width=FALSE, height=FALSE)
top.geometry('200x60+200+200')
top.configure(background='light blue')
top.option_add("*background", "light blue")
self.first_open_label6=Label(top,text='Your Choise:')
self.first_open_label6.place(x=10,y=25)
self.checkBox1=Checkbutton(top,text='First Choise', command=self.first_open_first, variable=self.first_open_var1)
self.checkBox1.place(x=90,y=10)
self.checkBox2=Checkbutton(top,text='Second Choise', command=self.first_open_second, variable=self.first_open_var2)
self.checkBox2.place(x=90,y=30)
def first_open_first(self):
# print "1o",self.first_open_var2.get()
if self.first_open_var1.get()==1:
self.list12.append("First Choice")
# print self.list12
self.checkBox2.deselect()
def first_open_second(self):
#print "2o",self.first_open_var2.get()
if self.first_open_var2.get()==1:
self.list12.append("Second Choise")
# print self.list12
self.checkBox1.deselect()
form1=Tk()
form1.title=('Something')
form1.resizable(width=FALSE, height=FALSE)
form1.geometry('250x130+200+200')
form1.configure(background='light blue')
form1.option_add("*background", "light blue")
dial_first_opening = First_Opening()
form1.destroy()
form1.mainloop()
What do you think is the problem?
Thanks in advance.
|

February 18th, 2013, 08:34 AM
|
 |
Contributing User
|
|
|
|
Code:
from Tkinter import *
class First_Opening():
def __init__(self):
top=Tk()
self.first_open_var1=IntVar(top) # master is a top level that isn't destroyed
self.first_open_var2=IntVar(top)
self.list12=[]
top.title('Program')
top.resizable(width=FALSE, height=FALSE)
top.geometry('200x60+200+200')
top.configure(background='light blue')
top.option_add("*background", "light blue")
self.first_open_label6=Label(top,text='Your Choise:')
self.first_open_label6.place(x=10,y=25)
self.checkBox1=Checkbutton(top,text='First Choise', command=self.first_open_first, variable=self.first_open_var1)
self.checkBox1.place(x=90,y=10)
self.checkBox2=Checkbutton(top,text='Second Choise', command=self.first_open_second, variable=self.first_open_var2)
self.checkBox2.place(x=90,y=30)
top.mainloop() #**************** run mainloop of top
def first_open_first(self):
print "1o",self.first_open_var1.get() ###### changed to var1
if self.first_open_var1.get()==1:
self.list12.append("First Choice")
print self.list12
self.checkBox2.deselect()
def first_open_second(self):
print "2o",self.first_open_var2.get()
if self.first_open_var2.get()==1:
self.list12.append("Second Choise")
print self.list12
self.checkBox1.deselect()
################if you had needed that other top level you could withdraw rather than destroy it.
dial_first_opening = First_Opening()
__________________
[code] Code tags[/code] are essential for python code!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|