Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 views
in Technique[技术] by (71.8m points)

python - Using .pack() and .grid() at the same time with tkinter

I have a program with some Label() widgets, some Button() widgets, some Text() widgets, and a few Entry() widgets. A couple of revisions ago, I didn't have the labels, and I had less Entry() widgets, and I mixed .pack() and .grid() as was convenient and I was fine. I had to do some refactoring, and added the extra widgets in the process - all the new things added used .grid(). Nothing about the other widgets changed. Now, I get an error along the lines of "unable to use grid in .", etc. (I can post the full error message if necessary). Why, and how can I fix this? (I can post code if necessary as well.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can't mix grid and pack with widgets that share the same parent.

Why? Because grid will try to lay widgets out, possibly growing or shrinking widgets according to various options. Next, pack will try to do the same according to its rules. This may require that it change widget widths or heights.

grid will see that widgets have changed size so it will try to rearrange the widgets accirding to its rules. pack will then notice that some widgets have changed size so it will rearrange the widgets according to its rules. grid will see that widgets have changed size so it will try to rearrange the widgets according to their rules. pack will then notice that some widgets have changed size so it will rearrange the widgets according to its rules. grid will see that ...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...