Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
doing something after been checked a checkbutton
#1
i want when i tick  'python' checkbutton in 'lng' checkbar in under program and then i push 'peek' button, it prints 'python'
i dont get any error ...but it doesnt work
why?....please help
this is my code
#!/usr/bin/python3

from tkinter import *
class Checkbar(Frame):
   def __init__(self, parent=None, picks=[], side=LEFT, anchor=W):
      Frame.__init__(self, parent)
      self.vars = []
      for pick in picks:
         var = IntVar()
         chk = Checkbutton(self, text=pick, variable=var)
         chk.pack(side=side, anchor=anchor, expand=YES)
         self.vars.append(var)
   def state(self):
      return map((lambda var: var.get()), self.vars)
   def __getitem__(self,key):
        return self.vars[key]
   
   
if __name__ == '__main__':
   root = Tk()
   lng = Checkbar(root, ['Python', 'Ruby', 'Perl', 'C++'])
   tgl = Checkbar(root, ['English','German'])
   lng.pack(side=TOP,  fill=X)
   tgl.pack(side=LEFT)
   lng.config(relief=GROOVE, bd=2)
   

   def allstates(): 
      
##      print(lng[0])
      
      if lng[0] == 1:
         print ('python')
        
      
   Button(root, text='Quit', command=root.quit).pack(side=RIGHT)
   Button(root, text='Peek', command=allstates).pack(side=RIGHT)
   root.mainloop()
Quote
#2
def allstates(): 
        if lng[0].get() == 1:
            print ('python')
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)