本文介绍了如何使 OptionMenu 保持相同的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个片段,它创建了一个 OptionMenu
小部件.
I have a snippet which creates an OptionMenu
widget.
...
options = ('White', 'Grey', 'Black', 'Red', 'Orange',
'Yellow', 'Green', 'Blue', 'Cyan', 'Purple')
var = StringVar()
optionmenu = OptionMenu(par, var, *options)
optionmenu.grid(column=column, row=row)
...
我遇到的一个问题是每次选择一个新选项时,小部件的宽度都会发生变化.我相信这是由于小部件中的文本改变了宽度.如何使小部件保持一致的宽度?
One problem I've encountered is every time a new option is selected, the width of the widget changes. I believe this is due to the text within the widget changing widths. How do I make the widget hold a consistent width?
推荐答案
当您使用 grid
命令将小部件放置在其父级时,让小部件填充其单元格(尝试 sticky="新"
)
When you use the grid
command to place the widget in its parent, have the widget fill its cell (try sticky="ew"
)
这篇关于如何使 OptionMenu 保持相同的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!