【问题标题】:cannot get columnspan to make button fill the row of a Tkinter frame无法获得 columnpan 以使按钮填充 Tkinter 框架的行
【发布时间】:2021-01-14 18:34:31
【问题描述】:

我已经看到了这个Python Tkinter - Set Entry grid width 100% 和这个columnspan in grid options dose't function(这更有用),但不知道如何让我的“重新绘制”按钮填充它所在行的宽度。无论我将小部件的列跨度设置为什么,它都不会改变按钮的宽度。该按钮与其他小部件位于一个框架中,并且该行上没有其他任何内容。

用于按钮的代码:

button_quit2 = tk.Button(root, text = "Replot", command = rangesReplot, relief = tk.GROOVE, padx =30, pady =20 )
button_quit2.grid(row = 10, column = 0, columnspan=2)

【问题讨论】:

  • 试试button_quit2.grid(row = 10, column = 0, columnspan=2,stikcy='nsew') ?
  • @CoolCloud 您能否将其发布为答案,我会接受。仅列跨度还不够吗?您的建议有效。
  • 这让我在接受之前等待,我想还有 2 分钟。

标签: python button tkinter grid columnspan


【解决方案1】:

要让它完全填满行,请使用sticky='nsew',例如:

button_quit2 = tk.Button(frame2, text = "Replot", command = rangesReplot, relief = tk.GROOVE, padx =30, pady =20 )
button_quit2.grid(row = 10, column = 0, columnspan=2,sticky=tk.N+tk.S+tk.E+tk.W) #same as sticky='nsew'

columnspan 将按钮分配为最多 2 列,但它并没有完全“填充”或拉伸 2 列。

【讨论】:

  • 您的术语不太正确。 columnspan 不会拉伸按钮。它只是为按钮分配多于一列的空间。
猜你喜欢
  • 2016-12-25
  • 1970-01-01
  • 1970-01-01
  • 2019-11-17
  • 2021-10-27
  • 1970-01-01
  • 2017-08-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多