与 tkinter 同时使用 .pack() 和 .grid() [英] Using .pack() and .grid() at the same time with tkinter

查看:56
本文介绍了与 tkinter 同时使用 .pack() 和 .grid()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,其中包含一些 Label() 小部件、一些 Button() 小部件、一些 Text() 小部件和一些 Entry() 小部件.几次修改前,我没有标签,而且我的 Entry() 小部件较少,我混合了 .pack() 和 .grid() 方便,我很好.我不得不进行一些重构,并在这个过程中添加了额外的小部件——所有添加的新东西都使用了 .grid().其他小部件没有任何变化.现在,我收到了无法在 . 中使用网格"等错误信息(如有必要,我可以发布完整的错误消息).为什么,我该如何解决这个问题?(如有必要,我也可以发布代码.)

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.)

推荐答案

您不能将 gridpack 与共享同一父级的小部件混合使用.

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

为什么?因为 grid 会尝试布置小部件,可能会根据各种选项增加或缩小小部件.接下来,pack 会尝试按照它的规则做同样的事情.这可能需要它更改小部件的宽度或高度.

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 将看到小部件已更改大小,因此它将尝试根据其规则重新排列小部件.pack 然后会注意到一些小部件的大小发生了变化,因此它会根据其规则重新排列小部件.grid 将看到小部件已更改大小,因此它将尝试根据其规则重新排列小部件.pack 然后会注意到一些小部件的大小发生了变化,因此它会根据其规则重新排列小部件.grid 会看到...

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 ...

这篇关于与 tkinter 同时使用 .pack() 和 .grid()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆