2

I am using a CalendarButton to get a date - no big deal. I have set it's location in the initial layout - also no probs. I am getting the window's location with window_loc = window.CurrentLocation()

What I want to do is change the location of the popup calendar to stay with the main window when it is dragged around the screen. I have tried the window.update route but get an error message Exception has occurred: TypeError update() got an unexpected keyword argument 'location' Is it possible to do this?? Any help appreciated

Tried the code supplied in answer & got

Exception has occurred: TypeError popup_get_date() got an unexpected keyword argument 'relative_location'

Not sure why

Update - solved using code:

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)

I get the popup to be where I want - with the main window.

Thanks

MarkT
  • 21
  • 2

1 Answers1

0

Maybe you get something wrong for the exception about window.update

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

It should like this

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

There's no method update for sg.Window, try window.move after window finalized.

move(x, y)

Move the upper left corner of this window to the x,y coordinates provided

To change the location of the popup calendar to stay with the main window, it's better to call sg.popup_get_date with option relative_location after one button clicked.

  • '<Configure>' event for the size of the widget changed. On some platforms, it can mean that the location changed.

Demo Code

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()
Jason Yang
  • 11,284
  • 2
  • 9
  • 23