Home > Software engineering >  how to make my button align in pack method
how to make my button align in pack method

Time:10-28

dates = [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]

month = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUNE', 'JULY', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']

year = [2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038,
        2039, 2040]

Date = StringVar(plane)
Date.set(dates[0])

Month = StringVar(plane)
Month.set(month[0])

Year = StringVar(plane)
Year.set(year[0])

date_option = OptionMenu(plane, Date, *dates)
month_option = OptionMenu(plane, Month, *month)
year_option = OptionMenu(plane, Year, *year)

date_option.config(font=("Arial", 18, "bold"))
month_option.config(font=("Arial", 18, "bold"))
year_option.config(font=("Arial", 18, "bold"))

date_option.pack(side="left", fill="x", expand="yes")
month_option.pack(side="left", fill="x", expand="yes")
year_option.pack(side="left", fill="x", expand="yes")

submit = Button(plane, text="Submit", font=("Engrave", 15, "bold"), fg="black", bg="silver")
submit.pack(side="right", padx=30)

Here I am unable to pack my submit button below the date entry dropbox if I pack submit button the button is placed next to the year option menu .

CodePudding user response:

It is easier to put those OptionMenu in a frame:

...
frame = Frame(plane)
frame.pack()

date_option = OptionMenu(frame, Date, *dates)
month_option = OptionMenu(frame, Month, *month)
year_option = OptionMenu(frame, Year, *year)
...

CodePudding user response:

You need to declare a new Frame to put the button in:

from tkinter import *

r = Tk()

r2 = Frame(r)
r2.pack(side = 'bottom')

Label(r, text = 'right') .pack(fill = 'x', side = 'right')
Label(r2, text = 'left') .pack(side = 'left')

r.mainloop()

Using .pack() is faster, but gives much less flexibility when creating GUIS, I'd recommend using .grid() for anything other than an experiment.

.pack() resources

  • Related