我有以下正在进行的代码,我试图让用户从日历中输入日期,但我对使用 tkinter、tkcalendar 非常陌生,所以我不确定如何将输入存储为我的变量可以传递到其他地方使用:
def addGameTimeInfo():
#week_number = input('Enter the week number of this game:')
#game_date = input('Enter the date for this game(YYYY/MM/DD):')
#season_number = input('Enter Season Number for this game:')
def calendar_view():
def print_sel():
print(cal.selection_get())
top = Toplevel(root)
cal = Calendar(top,
font="Arial 14", selectmode='day',
cursor="hand1")
cal.pack(fill="both", expand=True)
ttk.Button(top, text="ok", command=print_sel).pack()
def dateentry_view():
def print_sel(e):
print(cal.get_date())
top = Toplevel(root)
ttk.Label(top, text = 'Choose date').pack(padx=10,pady=10)
cal = DateEntry(top, width=12, background = 'darkblue',
foreground ='white',borderwidth=2)
cal.pack(padx=10,pady=10)
cal.bind('<<DateEntrySelected>>',print_sel)
root = Tk()
s = ttk.Style(root)
s.theme_use('clam')
ttk.Button(root, text = 'Calendar',command=calendar_view).pack(padx=10,pady=10)
ttk.Button(root,text='DateEntry',command=dateentry_view).pack(padx=10,pady=10)
root.mainloop()
我在另一篇文章中看到了这个问题,但我不能发表评论,因为我是新用户,否则我会在那里发帖。谢谢!