israel-dryer / ttkbootstrap

A supercharged theme extension for tkinter that enables on-demand modern flat style themes inspired by Bootstrap.
MIT License
1.79k stars 363 forks source link

Add height property to ttkbootstrap.Button(height=5) #504

Closed smatthys closed 8 months ago

smatthys commented 8 months ago

Is your feature request related to a problem? Please describe.

When creating a button with ttkbootstrap, I can specify a width but for some reason a height is not supported?

root = ttkb.Window(themename='superhero') button1 = ttkb.Button(root, width=15,height=5,wraplength=50,text = 'Click me!') button2 = ttkb.Button(root, width=15,height=5,wraplength=50,text = 'NOO, Click me!', bootstyle='primary, outline')

Describe the solution you'd like

I would love to be able to specify a button height and wraplength.

Describe alternatives you've considered

Making my buttons with standard Tkinter buttons.

Additional context

No response

rdbende commented 8 months ago

Why do you want to set a height for the button?

rdbende commented 8 months ago

Buttons aren't meant to have multiple lines of text. Plain ttk doesn't support it either.

smatthys commented 8 months ago

Buttons aren't meant to have multiple lines of text. Plain ttk doesn't support it either.

Why do you think 'height' is not supported in plain ttk? Did you try? I did and it worked perfectly. Is this the correct way, probably not but having the option for it would make it more line for line code compatible with vanila ttk.

rdbende commented 8 months ago
$ python3
Python 3.12.0 (main, Oct  2 2023, 00:00:00) [GCC 13.2.1 20230918 (Red Hat 13.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> from tkinter import ttk
>>> root = tkinter.Tk()
>>> button = ttk.Button(root, text="Spam Ham Egg", height=10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.12/tkinter/ttk.py", line 582, in __init__
    Widget.__init__(self, master, "ttk::button", kw)
  File "/usr/lib64/python3.12/tkinter/ttk.py", line 527, in __init__
    tkinter.Widget.__init__(self, master, widgetname, kw=kw)
  File "/usr/lib64/python3.12/tkinter/__init__.py", line 2629, in __init__
    self.tk.call(
_tkinter.TclError: unknown option "-height"
>>> 

_tkinter.TclError: unknown option "-height"

smatthys commented 8 months ago

from tkinter import import ttkbootstrap as ttkb from ttkbootstrap.constants import

root = ttkb.Window(themename='superhero') root.title('TTK Pack') root.geometry('400x600')

label1 = ttkb.Label(root, text = 'First label', background= 'red') label2 = ttkb.Label(root, text = 'Label 2', background= 'blue') label3 = ttkb.Label(root, text = 'Last of Us', background= 'green') button1 = Button(root, width=15,height=5,wraplength=50,text = 'Click me!') button2 = Button(root, width=15,height=5,wraplength=50,text = 'NOO, Click me!')#, bootstyle='primary, outline')

layout

label1.pack(side = 'top', expand=False) label2.pack(side = 'top', fill='x') label3.pack(side = 'top',pady=10) button1.pack(side = 'left', expand=True, fill='none') button2.pack(side = 'right', expand=True, fill='none')

root.mainloop()

rdbende commented 8 months ago

But that's not a ttk button

rdbende commented 8 months ago

FYI ttkbootstrap is an extension, and it can only do things that plain ttk widgets support.

smatthys commented 8 months ago

Ah OK, I thought that the ttk Button inherited from Tk() Button. I can set ipady=25 in the button pack, and add \n in the button text to recreate wraplenght, but it's not ideal. With height, the button never exceeds the set size even when wraplength is having multiline text, it's consistent. I like consistency. 😅

smatthys commented 8 months ago

Ok, I found customtkinter that does support height. It also doesn't wrap length, but with the fixed height, I can \n without changing the center text placement. Both buttons 1 and 2 are identical in size. The text also is centered and aligned. To close this, I want to thank all of you who are working on ttkbootstrap. It is an awesome addition to Tkinter and I would love to help implement those not-so-popular(or useful) attributes, but I'm a noob and still learning.

import customtkinter as ctk

setup

root = ctk.CTk() root.title('CTK pack') root.geometry('600x400')

Widgets

label1 = ctk.CTkLabel(root, text = 'First label', bg_color= 'red') label2 = ctk.CTkLabel(root, text = 'Label 2', bg_color= 'blue') label3 = ctk.CTkLabel(root, text = 'Last of Us', bg_color= 'green')

button1 = ctk.CTkButton(root, width=100, height=80, text = 'Click me!') button2 = ctk.CTkButton(root, width=100, height=80, text = 'NOO, \nClick me!')

layout

label1.pack(side = 'top', expand=False) label2.pack(side = 'bottom', fill='x') label3.pack(side = 'top',pady=10)

button1.pack(side = 'left', expand=True, fill='none') button2.pack(side = 'right', expand=True, fill='none')

root.mainloop()

rdbende commented 8 months ago

As someone who has learned a bit of UI/UX design, I'd be happier if customtkinter didn't support multi-line buttons, but yeah, some people need it, so it might be nice to have.

yxdragon commented 5 months ago

why ttkbootstrap.entry ’s height is bigger than ttk.entry? So I think there is some way to control the height?