tkinter按钮不接受高度参数

时间:2017-01-11 16:08:59

标签: python-3.x tkinter ubuntu-16.04

我有一个tkinter按钮,由于某种原因它接受width = xx,但不接受height = xx 我正在使用python3.5,默认情况下支持tkinter,在ubuntu 16.04上 这是代码示例:

# 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"
是不是可以上班?或者如果它是一个我应该报告它的错误?

3 个答案:

答案 0 :(得分:3)

这不是一个错误,这就是ttk按钮的工作方式。如果您需要高度可配置的按钮,请使用tkinter按钮。 ttk按钮的用途较少。 ttk小部件的目标是为您提供一组与特定主题一致的按钮。

由于您使用的是Linux系统,因此可以通过packplacegrid使用适当的选项来影响高度,但它不如height选项方便

答案 1 :(得分:0)

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

答案 2 :(得分:0)

不要那样导入:

from tkinter.ttk import *

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