tkinter 按钮不接受高度参数

tkinter button doesn't accept height parameter

我有一个 Tkinter 按钮,出于某种原因,它接受 width=xx,但不接受 height=xx

我在 ubuntu 16.04

上使用 Python 3.5,默认支持 Tkinter

这是代码示例:

# works: button_enter = ttk.Button(self.frm,  text='ok', width = 100)
# works: button_enter.config(width=25)
# fails: button_enter = ttk.Button(self.frm,  text='ok', height=15, width = 25)
# fails: button_enter.config(width=25, height=15)
button_enter = ttk.Button(self.frm,  text='ok')
button_enter.config(width=25)
button_enter['command'] = self.some_method
button_enter.grid(column=2, row = 0, sticky=W)

这是我遇到的错误:

Traceback (most recent call last):
  File "pygo.py", line 44, in <module>
    app = App()
  File "pygo.py", line 34, in __init__
    button_enter.config(height=15, width=25)
  File "/usr/lib/python3.5/tkinter/__init__.py", line 1333, in configure
    return self._configure('configure', cnf, kw)
  File "/usr/lib/python3.5/tkinter/__init__.py", line 1324, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown option "-height"

它可以工作吗?或者如果它是一个错误,我应该在哪里报告它?

这不是错误,这就是 ttk 按钮的工作原理。如果您需要高度可配置的按钮,请使用 tkinter 按钮。 ttk 按钮的可配置性较低。 ttk widgets 的目标是为您提供一组与特定主题一致的按钮。

由于您使用的是 linux 系统,您可以使用 packplacegrid 以及适当的选项来影响高度,尽管它不如height 选项。

使用 Place() 方法代替 Grid() 或 Pack() 或 Config() 。它会工作正常。我从未使用过 Config() 方法

不要那样导入:

from tkinter.ttk import *

如果使用此方法导入,按钮将被导入为 ttk