vendredi 17 février 2017

which checkbutton has been checked

i have creted a checkbox. i want the program prints 'python' when i tick it in created checkbox. but it doesnt work...i dont get error but it doesnt print 'python' 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()




Aucun commentaire:

Enregistrer un commentaire