1

I can't seem to resize a button I'm trying to make on tkinter, this is my first time using tkinter so I don't know too much, is this how it is meant to be done or is there a better or easier way? Whenever i try to run the code it says tkinter.tclerror unknown option "-height", the code I'm using is below. Thanks

from tkinter.ttk import *
...
myButton = Button(gui, text="Continue", height = 100, width = 100)
myButton.grid(row=10, column=2)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Rhys34512
  • 39
  • 5
  • 1
    I think you are using `ttk.Button` instead of `tkinter.Button`. Did you have a line `from tkinter.ttk import *` after `from tkinter import *` in your code? – acw1668 Jul 16 '20 at 08:18
  • Hi, yeah I have 'from tkinter.ttk import *' just under 'from tkinter import *' – Rhys34512 Jul 16 '20 at 08:21
  • Just make it `from tkinter import *` It'll work fine – Ayush Jain Jul 16 '20 at 08:23
  • This way of importing modules is not recommended. Change them to `import tkinter as tk` and `import tkinter.ttk as ttk`. Then use `tk.Button(...)` instead of `Button(...)`. – acw1668 Jul 16 '20 at 08:24

1 Answers1

1

Probably you use the ttk.Button instead of tkinter.Button (ttk one doesn't have height and width parameters).

I have written an example for you.

Code:

import tkinter as tk  # Should use the tkinter module

root = tk.Tk()

original = tk.Button(root, text="Original")
original.grid(row=1, column=1)

resized = tk.Button(root, text="Resized", height=20, width=20)
resized.grid(row=2, column=1)

tk.mainloop()

GUI:

GUI Result

Note:

Here is a ttk.Button resizing related SO question: Changing ttk Button Height in Python

milanbalazs
  • 4,811
  • 4
  • 23
  • 45