Tkinter - Sorting the checkboxes and printing if they're clicked
Question: I'm learning Tkinter and have two questions.

[1st one answered in the comment section]

1 - Why do the items in the dictionary are not printed in the correct order?
If you delete the "grid" part from the Button, you may see that they are not
ordered.

2 - Why the button is not shown? I want to make a button just below the
checkboxes, which will print out "1" for each clicked checkboxes.

[This link](http://stackoverflow.com/questions/8536518/how-do-i-create-
multiple-checkboxes-from-a-list-in-a-for-loop-in-python-tkinter) was my
reference.

Below is my code:

    
    
    from Tkinter import *
    
    master = Tk()
    
    def read():
        print dict[mini].get()
    
    dict = {"first": 0, "second": 0, "third": 0}
    
    
    for mini in dict:
        dict[mini] = Variable()
        l = Checkbutton(master, text=mini, variable=dict[mini])
        l.grid(sticky=W, pady=4)
        l.pack()
    
    Button(master, text='Show', command=read).grid(row=len(dict) + 1, sticky=W, pady=4)
    
    master.mainloop()
    

Edit: Spelling


Answer: The button does not show because the program errors out at the `pack`
statement. Remove the `pack()` and the button shows. You can not mix `grid`
and `pack` in the same container. (from what Curly Joe said in the comments).

The `Tkinter` variable declared in `my_dict` are not initialized nor assigned
and therefore cannot be used; the dictionary of Variable()s is never changed.

    
    
    from Tkinter import *
    from collections import OrderedDict
    
    master = Tk()
    
    def read():
        try:
            print my_dict[mini]
        except KeyError:
            pass
    
    my_dict = OrderedDict()
    my_dict["first"] = 0
    my_dict["second"] = 0
    my_dict["third"] = 0
    
    
    for mini in my_dict.keys():
        my_dict[mini] = Variable()
        chkbtn = Checkbutton(master, text=mini, variable=my_dict[mini])
        chkbtn.grid(sticky=W, pady=4)
    
    Button(master, text='Show', command=read).grid(row=len(my_dict) + 1, sticky=W, pady=4)
    
    master.mainloop()
    

Finally, do not use `i`, `l`, or `o` as single character variable names as it
can be difficult to tell which is a letter and which is a number; also do not
use the name of `builtins` for your `variables` or `method` names.

