PySimpleGUI中CalendarButton弹窗日历随主窗口移动的实现问题
实现日历弹窗随主窗口拖拽同步移动
问题背景
使用PySimpleGUI的CalendarButton获取日期,已在初始布局中设置其位置,通过window.CurrentLocation()获取主窗口位置,需求是拖拽主窗口时,弹出的日历窗口能随之移动。
尝试过的失败方案
- 调用
window.update()方法,触发TypeError,提示该方法不支持location参数。 - 使用带
relative_location参数的popup_get_date()调用方式,触发TypeError,提示该函数不支持relative_location参数。
最终解决方法
直接将popup_get_date()的location参数指定为主窗口的当前位置,即可实现日历弹窗随主窗口拖拽同步移动。代码示例:
elif event == 'Date': main_window_location = window.CurrentLocation() chosen_mon_day_year = sg.popup_get_date(location=main_window_location) if chosen_mon_day_year: window['-IN-'].update(chosen_mon_day_year)
内容的提问来源于stack exchange,提问作者MarkT
相关产品推荐
相关产品推荐

