如何使我的按钮对齐在包方法


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)

在这里,我无法将我的提交按钮打包在日期条目dropbox下面,如果我打包提交按钮,按钮被放置在年份选项菜单旁边。

将这些OptionMenu放在一个框架中更容易:

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

你需要声明一个新的Frame来放置按钮:

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()

使用.pack()更快,但在创建gui时灵活性要小得多,我建议在除实验之外的任何情况下使用.grid()。

.pack资源()

最新更新