Если вы хотите лучшего выравнивания, то не используйте width
, height
, place()
, но pack()
и grid()
и его параметры.Если вы используете неправильную опцию в pack()
, grid()
, вы увидите сообщение об ошибке со всеми доступными опциями для pack
или grid
.pack
и grid
используют разные параметры.
Подробнее в документации: place () , pack () , grid ()
![enter image description here](https://i.stack.imgur.com/g73JD.png)
import tkinter as tk
from tkinter import messagebox
def pd():
if var1.get():
l1.config(text="You Have Selected Pendrive")
else:
l1.config(text="")
def mcard():
if var2.get():
l2.config(text="You Have Selected Memory card")
else:
l2.config(text="")
def hdd():
if var3.get():
l3.config(text="You Have Selected HDD")
else:
l3.config(text="")
def per():
print("Successfully compiled")
msgbox = messagebox.askquestion("Closing program","Are you sure?",)
if msgbox == "yes":
win.destroy()
else:
messagebox.showinfo('Return', 'You will now return to the application screen')
win = tk.Tk()
win.geometry("500x500+0+0")
var1 = tk.IntVar()
var2 = tk.IntVar()
var3 = tk.IntVar()
cb1 = tk.Checkbutton(win, text="Pendrive", variable=var1, font=5, cursor="dot", bg="grey", anchor="w", command=pd)
cb2 = tk.Checkbutton(win, text="Memory Card", variable=var2, font=5, cursor="dot",bg="grey", anchor="w", command=mcard)
cb3 = tk.Checkbutton(win, text="HDD", variable=var3, font=5, cursor="dot", bg="grey", anchor="w", command=hdd)
cb1.pack(ipadx=10, ipady=10, fill='both', expand=True)
cb2.pack(ipadx=10, ipady=10, fill='both', expand=True)
cb3.pack(ipadx=10, ipady=10, fill='both', expand=True)
l1 = tk.Label(win, background='#bbbbbb')
l2 = tk.Label(win, background='#cccccc')
l3 = tk.Label(win, background='#bbbbbb')
l1.pack(ipadx=10, ipady=10, fill='both', expand=True)
l2.pack(ipadx=10, ipady=10, fill='both', expand=True)
l3.pack(ipadx=10, ipady=10, fill='both', expand=True)
b1 = tk.Button(win, text="Submit", command=per)
b1.pack(side='bottom', ipadx=10, ipady=10, fill='both', expand=True)
win.mainloop()