pleabargain

simple TK menu need to learn more about tk

May 4th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. #like to know how to do more of this kind of work
  2. #how to work with classes?
  3. #so much to know!
  4. #there's no title for this button box
  5. #all content is written to terminal
  6. #I would want to write it to a file...
  7.  
  8. import tkinter as tk
  9.  
  10. class GUI(tk.Tk):
  11.     def __init__(self):
  12.         tk.Tk.__init__(self)
  13.  
  14.         #the output of the dictionary items are not kept the same!
  15.         self.buttonDic = {
  16.         'has purchased seat blocks':0,
  17.         'prefer to work directly with hotel':0,
  18.         '':0,
  19.         'Black Beans':0
  20.         }
  21.  
  22.         for key in self.buttonDic:
  23.             self.buttonDic[key] = tk.IntVar()
  24.             aCheckButton = tk.Checkbutton(self, text=key,
  25.                                             variable=self.buttonDic[key])
  26.             aCheckButton.grid(sticky='w')
  27.  
  28.         submitButton = tk.Button(self, text="Submit",
  29.                                         command=self.query_checkbuttons)
  30.         submitButton.grid()
  31.  
  32.     def query_checkbuttons(self):
  33.         for key, value in self.buttonDic.items():
  34.             state = value.get()
  35.             if state != 0:
  36.                 print(key)
  37.                 self.buttonDic[key].set(0)
  38.  
  39. gui = GUI()
  40. gui.mainloop()
Add Comment
Please, Sign In to add comment