也许你对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()