-1

I'm trying to create 3 sets of checkbox lists of varying lengths and then display them in three columns on a page within a tkinter GUI. List 1 will be a Integer based list, 2 & 3 are Strings. The variables for the names of these lists are defined earlier in the code before the GUI starts. N_index = [1, 2, 3] T_index = [T1, T2, T3] P_index = [P1, P2, P3]

The lengths of the lists will change each time the code is run so I have used this:

N_leng = range(1, int(len(N_index)+1)) T_leng = range(1, int(len(T_index)+1)) P_leng = range(1, int(len(P_index)+1))

The code I have partially used to create my GUI is taken from here Switch between two frames in tkinter (Thank-you)

I'm trying to put these lists into Page One.

class PageOne(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        f = tk.Frame(self)
        f.pack(side="left")

        label = ttk.Label(f, text="Page One", font=LARGE_FONT)
        label.pack(pady=10, padx=10)

I then have the 3 sets of checkboxes. When I run the code it runs and never finishes. However it doesn't throw up an error even in debugging mode. Can someone spot my mistake?

    def ckbox_params():
        for i, j in zip(N_index, N_leng):
            ivar = tk.IntVar()
            N_selection1 = tk.Checkbutton(f, text="%d" % i, variable=ivar, onvalue=i, offvalue="")
            N_selection1.grid(sticky="nw", pady=4)

        for i, k in zip(T_index, T_leng):
            svar = tk.StringVar()
            T_selection1 = tk.Checkbutton(f, text="%s" % i, variable=svar, onvalue=i, offvalue="")
            T_selection1.grid(sticky="nw", pady=4)

        for i, l in zip(P_index, P_leng):
            svar = tk.StringVar()
            P_selection1 = tk.Checkbutton(f, text="%s" % i, variable=svar, onvalue=i, offvalue="")
            P_selection1.grid(sticky="nw", pady=4)
    ckbox_params()`

Any suggestions, ideas or solutions would be helpful as to what I've done wrong.

Thank you

Community
  • 1
  • 1
OParker
  • 265
  • 1
  • 5
  • 19
  • Where do you create your root window? How does `ckbox_params` know about `f`? It would help if you post a [mcve]. – PM 2Ring Apr 22 '16 at 11:33
  • Why are you doing `int(len(...))`? `len` returns an int. – Bryan Oakley Apr 22 '16 at 11:52
  • Sorry PM 2Ring I didn't know how much information you'd need. I'm very new to all this and this is my first try with OOP so I do make mistakes. – OParker Apr 22 '16 at 12:27

1 Answers1

1

The problem is that you are using pack for the label, and grid for the checkboxes, but both the label and checkbox share the same parent.

class PageOne(tk.Frame):

    def __init__(self, parent, controller):
        ...
        label = ttk.Label(f, text="Page One", font=LARGE_FONT)
        label.pack(pady=10, padx=10)
        ...
        N_selection1 = tk.Checkbutton(f, text="%d" % i, variable=ivar, onvalue=i, offvalue="")
        N_selection1.grid(sticky="nw", pady=4)
        ...

You cannot mix pack and grid in that way. For all widgets directly inside f you must use one or the other.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685