【问题标题】:PySimpleGUI - CalendarButtonPySimpleGUI - 日历按钮
【发布时间】:2022-10-16 12:38:44
【问题描述】:

我正在使用 CalendarButton 来获取日期 - 没什么大不了的。我已经在初始布局中设置了它的位置 - 也没有问题。 我正在使用 window_loc = window.CurrentLocation() 获取窗口的位置

我想要做的是更改弹出日历的位置以在屏幕上拖动时与主窗口保持一致。 我尝试了 window.update 路由,但收到错误消息 发生异常:TypeError update() 得到了一个意外的关键字参数“位置” 是否有可能做到这一点?? 任何帮助表示赞赏

尝试了答案中提供的代码并得到了

发生异常:TypeError popup_get_date() 得到了一个意外的关键字参数“relative_location”

不知道为什么

【问题讨论】:

    标签: pysimplegui


    【解决方案1】:

    也许你对window.update 的异常有什么误解

    TypeError update() got an unexpected keyword argument 'location' 
    

    它应该像这样

    AttributeError: 'Window' object has no attribute 'update'
    

    sg.Window 没有方法update,在窗口完成后尝试window.move。

    移动(x,y)

    将此窗口的左上角移动到提供的 x,y 坐标

    要更改弹出日历的位置以与主窗口保持一致,最好在单击一个按钮后使用选项relative_location 调用sg.popup_get_date。

    • '<Configure>' 小部件大小的事件已更改。在某些平台上,这可能意味着位置发生了变化。

    演示代码

    import PySimpleGUI as sg
    
    layout = [[sg.Input(key='-IN-'), sg.Button('Date')]]
    window = sg.Window('Title', layout, finalize=True)
    relative_location = (None, None)
    left, top = window.current_location()
    window.bind('<Configure>', "Configure")
    
    while True:
    
        event, values = window.read()
    
        if event == sg.WINDOW_CLOSED:
            break
        elif event == 'Configure':
            new_left, new_top = window.current_location()
            relative_location = new_left - left, new_top - top
        elif event == 'Date':
            chosen_mon_day_year = sg.popup_get_date(relative_location=relative_location)
            if chosen_mon_day_year:
                window['-IN-'].update(chosen_mon_day_year)
    
    window.close()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-04
      • 2012-02-13
      • 2011-12-11
      相关资源
      最近更新 更多