When I define the following function, all the other widgets that I define inside the function are appearing and are functional. I can modify the entries and get the values from them.
`
def frame(self):
new_frm = tk.Frame(self.window, width=200,
height=200, bg="white"
).place(x=self.x0, y=0)
self.frame_list.append(new_frm)
lbl = tk.Label(master=new_frm, relief=tk.RIDGE,
text=param_name, fg = "white", bg="black",
anchor="w", font=("Arial", 20)
)
lbl.place(x = self.x0, y = 0)
self.x0 += 205
`
But if I change the code to below, only the frame appears and not the widgets. But, the widgets are still as functional as the first case. I wonder why this happens and how I can fix it.
`
def frame(self):
new_frm = tk.Frame(self.window,
width=200, height=200, bg="white"
)
new_frm.place(x=self.x0, y=0)
new_frm = tk.Frame(self.window, width=200, height=200, bg=color)
self.frame_list.append(new_frm)
lbl = tk.Label(master=new_frm, relief=tk.RIDGE,
text=param_name, fg = "white", bg="black",
anchor="w", font=("Arial", 20)
)
lbl.place(x = self.x0, y = 0)
self.x0 += 205
`
I want to put the new_frm into frame_list
so I can get access to all frames later. Of course, when I use new_frm = tk.Frame(self.window, width=200,height=200, bg="white").place(x=self.x0, y=0)
, the new_frm
become a Nonetype and it doesn't work.
Update:
The solution mentioned by @Kartikeya is to use .grid()
for widgets inside the frame. Therefore, the code must be written this way:
`
def frame(self):
new_frm = tk.Frame(self.window,
width=200, height=200, bg="white"
)
new_frm.place(x=self.x0, y=0)
new_frm = tk.Frame(self.window, width=200, height=200, bg=color)
self.frame_list.append(new_frm)
lbl = tk.Label(master=new_frm, relief=tk.RIDGE,
text=param_name, fg = "white", bg="black",
anchor="w", font=("Arial", 20)
)
lbl.grid(row = 0, column = 0)
self.x0 += 205
`