My problem is this. I create a tkinter widget and later down the road I create a new frame that I want to add this widget to. When I call .grid() on the widget the widget is placed on the first frame, not the newer one that I want it to be on.
1 Answer
By default a widget is managed by its parent. If you don't want that, use the parameter in_ when calling pack, place or grid.
For example:
self.f1 = tk.Frame(...)
self.label = tk.Label(self.f1, ...)
self.label.pack(...)
...
self.f2 = tk.Frame(...)
self.label.pack(in_=self.f2, ...)
However, if you find yourself doing this a lot, you're probably doing something wrong. This is almost never necessary in most tkinter applications.
3 Comments
Jonah Fleming
@ranger Can't you just do label=Label(frame1).grid()?
Bryan Oakley
@JonahFleming: that creates a whole new label, rather than moving an existing label. Yes, you can do it if you actually want to create more widgets.
Jonah Fleming
Ok. I get what he is asking now!