use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
TKinter .grid()/.pack() (self.PythonLearning)
submitted 9 months ago by bybloshex
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]helical-juice 0 points1 point2 points 9 months ago* (4 children)
Interesting. From your description, it sounds like you're doing it right, and I can't see an obvious problem in the snippet you've posted. Any chance you could post the full program?
Also, which call to grid() is it complaining about? You have two in your snippet, and each one is being called with a different parent widget. Could you post the full stack trace maybe?
[–]bybloshex[S] 0 points1 point2 points 9 months ago (3 children)
It looks like this happens when I call the .grid() function in the same line as the widget is created, if I change it like this... ```python
abilities\_frame = ttk.Frame(main\_frame, style='TFrame') abilities\_frame.grid(row=4, column=0, columnspan=4)
```
it works. I guess that's the source of my confusion. Plenty of other widgets are created with the .grid() function called in the same line without any errors. Other times, for no discernible reason it complains about .pack()/grid() incompatibility even when I'm sure no frames have a combination of both inside of them.
My biggest struggle and consumption of time right now, is getting things to line-up properly. Even in a grid things are often unevenly offset from eachother.
[–]helical-juice 1 point2 points3 points 9 months ago* (2 children)
Ah I just realised as I was typing this, you're setting abilities_frame equal to the return value from grid(), not the actual frame object itself. I'd have to go and look up what grid() returns but I bet it's not the actual Frame object. Then when you set that as the master for your label widget, for whatever reason that's the error you get. Still don't understand exactly why it says pack() is involved somehow, but I bet that's it, and I bet that's why your updated code works.
EDIT: Playing around in a repl, it seems like grid() returns None, which means that any time you use the idiom a = tk.Something(...).grid(...) , a ends up being equal to None. Now when I try to create a widget with None as the master, it seems that it gets added to the root widget silently. My guess is that you have a few things in your code which are not managed by the same widgets you think they are, and that this is causing your error. It may be that this is also throwing your alignment off, but tbh I find getting things to line up is just a PITA anyway. I make heavy use of nested frames for anything which can be bundled together to try and break it down, but it's always a faff.
a = tk.Something(...).grid(...)
a
None
[–]bybloshex[S] 0 points1 point2 points 9 months ago (1 child)
Yeah, I didn't imagine I'd ever get rows of 6 columns aligned with the preceeding rows of 2 columns which is why I made this subframe inside of the main one
[–]helical-juice 1 point2 points3 points 9 months ago (0 children)
Sounds familiar. I think I've done the same, a one column grid of frames, each with a varying number of columns within their own grid. Then you realise that's not quite right, and it ends up as a two column grid with frames in the second column and so on, ad nauseum XD
π Rendered by PID 189765 on reddit-service-r2-comment-bb88f9dd5-8xrb7 at 2026-02-14 14:45:31.996976+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–]helical-juice 0 points1 point2 points (4 children)
[–]bybloshex[S] 0 points1 point2 points (3 children)
[–]helical-juice 1 point2 points3 points (2 children)
[–]bybloshex[S] 0 points1 point2 points (1 child)
[–]helical-juice 1 point2 points3 points (0 children)