1

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
  • Please add relevant code. Commented Nov 2, 2015 at 22:49

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

@ranger Can't you just do label=Label(frame1).grid()?
@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.
Ok. I get what he is asking now!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.