mardi 24 janvier 2017

Python, Tkinter: Making a grid of Checkboxes using Lists

I'm trying to make a tkinter program that hass a 3x3 grid of checkboxes, the code I have created to do this is:

self.strCategories=("Q","W","E","R","T","Y","U","I","O")
self.varCategories={}
for x in self.strCategories:
    self.varCategories[x] = tk.IntVar()

self.chckbxCategories={}
for i in range(3):
    for j in range(3):
        self.chckbxCategories[self.strCategories[i*3+j]] = tk.Checkbutton(self, text=self.strCategories[i*3+j], font=('Lucida Grande',15), anchor='w', bg='#FFFFFF' , variable=self.varCategories[self.strCategories[i*3+j]], onvalue=1, offvalue=0)
        self.chckbxCategories[self.strCategories[i*3+j]].place(relx=10/4 + 11*i/4, rely=7/20 + 4*j/20, relwidth=10/40, relheight=5/20)

However, the widgets don't appear on the screen! If I replace the .place with some other geometry manager it works (I'd like to use .place because it's relx and rely handle resizing the screen for me) so I know the problem is not with making the widgets but with placing them.

What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire