简体   繁体   中英

python return value from calendar widget class

Is there an easy way to return the user selected date value to another python script using this code for a python calendar widget? I've saved the calendar widget in its own file named CalendarWidget.py. I have a main gui with a button that opens the calendar widget.

def callback():
    t=tk.Toplevel()
    t.title("Calendar")
    cal = CalendarWidget.Calendar(t, firstweekday=calendar.SUNDAY)
    cal.pack(expand=1, fill="both")
    cal.selection 

This is working fine. Now I just want to utilize the date. With the instance of cal.selection, I have tried saving the date. However, I am finding the cal.selection line is interpreted before the actual selection is saved. Thus I get a value of None for the calendar widget date.

Thanks for your consideration.

您可以通过以下方法解决此问题:更改实现,例如在关闭Toplevel实例时(即返回cal.selection ,或添加一个按钮,其回调都返回cal.selection并销毁小部件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM