Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 18th, 2013, 07:10 AM
Harris03 Harris03 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 13 Harris03 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old February 18th, 2013, 08:34 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,387 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 10 m 30 sec
Reputation Power: 383
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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Tkinter-Checkbutton's variable doesn't change

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap