diff --git a/Applications/Calendar/calendar.py b/Applications/Calendar/calendar.py index 4f80787..2bb8b43 100644 --- a/Applications/Calendar/calendar.py +++ b/Applications/Calendar/calendar.py @@ -1,32 +1,36 @@ from tkinter import * +from tkinter import ttk import calendar +from datetime import datetime win = Tk() win.title("GUI Calendar") -def text(): - year_str = year.get() - month_str = month.get() - year_int = int(year_str) - month_int = int (month_str) - cal = calendar.month(year_int, month_int) +def show_calendar(event=None): + yr = int(year_var.get()) + mo = months.index(month_var.get()) + 1 + cal = calendar.month(yr, mo) textfield.delete(0.0, END) textfield.insert(INSERT, cal) -label1 = Label(win, text = '{Year} ') -label1.grid(row = 0, column = 0) -label1 = Label(win, text = '{Month} ') -label1.grid(row = 0, column = 1) +years = [str(y) for y in range(1947, 2151)] +months = [calendar.month_name[m] for m in range(1, 13)] -year = Spinbox(win, from_= 1947, to = 2150, width = 24) -year.grid(row = 1, column = 0, padx = 16) -month = Spinbox(win, from_= 1, to = 12, width = 3) -month.grid(row = 1, column = 1) +year_var = StringVar(value=str(datetime.now().year)) +month_var = StringVar(value=calendar.month_name[datetime.now().month]) -button = Button(win, text = "{GO}", command = text) -button.grid(row = 1, column = 2) +Label(win, text="Year:").grid(row=0, column=0) +year_combo = ttk.Combobox(win, textvariable=year_var, values=years, width=6) +year_combo.grid(row=1, column=0) -textfield = Text(win, height = 10, width = 30, foreground = 'brown') -textfield.grid(row = 3, columnspan = 3) +Label(win, text="Month:").grid(row=0, column=1) +month_combo = ttk.Combobox(win, textvariable=month_var, values=months, width=10) +month_combo.grid(row=1, column=1) + +Button(win, text="Show Calendar", command=show_calendar).grid(row=1, column=2) +textfield = Text(win, height=10, width=30, fg='brown') +textfield.grid(row=3, columnspan=3) + +win.bind('', show_calendar) win.mainloop()