我用CalendarButton来约会-没什么大不了的。我已经设置了它的位置,在最初的布局-也没有问题。我使用window_loc = window.CurrentLocation()获取窗口的位置
我想要做的是更改弹出日历的位置,以便在主窗口被拖动到屏幕周围时保持在主窗口中。我尝试过window.update路由,但是出现了错误消息异常: TypeError update()获得了一个意外的关键字参数'location‘,可以这样做吗?感谢你的任何帮助
尝试了在答案和got中提供的代码
异常发生: TypeError popup_get_date()得到了一个意外的关键字参数'relative_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)
我把弹出式弹出弹出到我想要的地方-和主窗口。
谢谢
发布于 2022-10-14 05:17:10
也许你对window.update
的例外有些误解
TypeError update() got an unexpected keyword argument 'location'
它应该喜欢这个
AttributeError: 'Window' object has no attribute 'update'
没有用于update
的sg.Window
方法,在窗口完成后尝试window.move
。
移动(x,y)
将此窗口的左上角移动到所提供的x,y坐标。
若要更改弹出日历的位置以保留主窗口,最好在单击一个按钮后使用选项relative_location
调用relative_location
。
小部件大小的
'<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()
https://stackoverflow.com/questions/74064426
复制相似问题