1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| from tkinter import Tk, Label, Button, Frame
from tkinter.font import Font
def set_uniform_button_width(buttons):
max_length = max(len(button["text"]) for button in buttons)
for button in buttons:
button.config(width=max_length)
home = Tk()
home.columnconfigure(0, weight=1)
home.rowconfigure(0, weight=1)
family_font, size_font = "Helvetica", 10
custom_font = Font(family=family_font, size=size_font)
center_frame = Frame(home)
q1 = Label(
center_frame,
text="Quelle est la capitale de l'Algérie ?",
justify="center",
font=custom_font,
)
q1.pack()
button_texts = ["Oran", "Alger", "Annabal"]
buttons = []
for text in button_texts:
button = Button(center_frame, text=text, font=custom_font)
button.pack()
buttons.append(button)
center_frame.grid(row=0, column=0)
set_uniform_button_width(buttons=buttons)
home.mainloop() |
Partager