0

I have a Tkinter button, and for some reason, it accepts width=xx, but not height=xx

I'm using Python 3.5, with Tkinter support by default, on ubuntu 16.04

Here's the code sample:

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

Here is the error I'm getting:

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"

Can it be made to work? Or if it's a bug, where should I report it?

4

It's not a bug, that's just how ttk buttons work. If you need a highly configurable button, use a tkinter button. ttk buttons are less configurable on purpose. The goal of ttk widgets is to give you a set of buttons consistent with a particular theme.

Since you're on a linux system you can affect the height with pack, place or grid with appropriate options, though it's less convenient than the height option.

4
  • thanks for the answer but, how do i make tkinter button less ugly then ? it seems as if it escaped from 1992 ;)
    – freeaks
    Jan 11 '17 at 16:34
  • @freeaks: if you want less-ugly buttons, use ttk buttons and don't try to make them artificially tall. Or, like I said, try making them taller with the appropriate options to pack, place or grid. That usually won't affect windows or OSX ttk buttons since that platform has strict guidelines about how native buttons should look. Jan 11 '17 at 16:35
  • You can make a ttk button taller if you pack it into a frame and set the size of the frame.
    – patthoyts
    Jan 11 '17 at 16:38
  • my goal was to make the button the same height as the ttk Entry widget. by default Entry is like 10 and button like 20 in height (value are just to illustrate, not real height values)
    – freeaks
    Jan 11 '17 at 16:41
0

Use the Place() method instead over Grid() or Pack() or Config() . It will work fine. I never used Config() method

0

Don't import like that:

from tkinter.ttk import *

If you import with this method, the button will be imported as ttk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.