You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 18:31:17