I created a button using ttk.button and put text on it, but the text is not centered inside the button, I have already tried using ttk.Style() but it seems that it is not being applied, what could be happening?
from textwrap import fill
import tkinter as tk
from turtle import bgcolor, heading, width
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from PIL import Image, ImageTk
class APP:
def __init__(self):
# Criando a janela principal
self.root = tk.Tk()
self.root.title("Test")
self.root.geometry("1080x600") # Define o tamanho da janela
# Impede o redimensionamento da janela
self.root.resizable(False, False)
# Carregando a imagem existente
background_image = Image.open("background.png")
# Convertendo a imagem para o formato Tkinter PhotoImage
self.background_photo = ImageTk.PhotoImage(background_image)
# Criando um rótulo com a imagem como plano de fundo
self.background_label = tk.Label(
self.root, image=self.background_photo)
self.background_label.place(x=0, y=0, relwidth=1, relheight=1)
style_button = ttk.Style()
style_button.theme_use("litera")
style_button.configure("TButton", padx=5, pady=10, anchor="w")
# Criando o frame do Dataset
self.dataset_frame = ttk.Frame(self.root, height=10)
self.dataset_frame.grid(row=0, column=0, pady=10, padx=5)
self.dataset_label = ttk.Label(
self.dataset_frame, text="Dataset: ", bootstyle="inverse-primary", width=47)
self.dataset_label.configure(font=("Arial", 14, "bold"))
self.dataset_label.pack(side=LEFT, fill="x")
self.directory_entry = ttk.Entry(
self.dataset_frame, width=55, bootstyle="primary")
self.directory_entry.place(
relx=0.5, rely=0.5, relheight=0.9, anchor="center")
self.directory_button = ttk.Button(
self.dataset_frame, style="TButton", text="Selecionar")
self.directory_button.place(
relx=0.92, rely=0.5, relheight=0.8, anchor="center")
# Criando o frame do preview
self.preview_frame = tk.Frame(self.root)
self.preview_frame.grid(row=0, column=1, pady=10, padx=5)
self.preview_label = ttk.Label(
self.preview_frame, text="Preview: ", bootstyle="inverse-primary", width=48)
self.preview_label.configure(font=("Arial", 14, "bold"))
self.preview_label.pack(side=LEFT, fill="both")
# Inicia o loop principal da aplicação
self.root.mainloop()
# Inicializa a aplicação
app = APP()
An example of how it looks, I wanted to center the text inside the button:
