Adam
Adam

Reputation: 1

adding event to calendar in pysimplegui using python

I have added pysimplegui calendar and I have added another window to add events. I am looking for a way to show events inside calendar ? please give some ideas

Upvotes: 0

Views: 799

Answers (1)

Jason Yang
Jason Yang

Reputation: 13051

Two ways to get date

  • Using a CalendarButton element with an enable_events=True Input element, the event will be the key of the Input element.
  • Using a general Button element with an Input element, the event will be the key of the Button element to call function popup_get_date and update the date to the Input element if date selected.
import PySimpleGUI as sg

layout = [
    # First way
    [sg.Input(readonly=True, enable_events=True, key='INPUT 1'),
     sg.CalendarButton('Calendar 1', close_when_date_chosen=True, format='%Y-%m-%d', key='Calendar 1')],
    # Second way
    [sg.Input(readonly=True, key='INPUT 2'),
     sg.Button('Calendar 2')],
]
window = sg.Window('Calendar Button', layout)

while True:

    event, values = window.read()

    if event == sg.WIN_CLOSED:
        break
    print(event)
    if event == 'Input 1':
        print(values[event])
    elif event == 'Calendar 2':
        date = sg.popup_get_date(close_when_chosen=True)
        if date:
            m, d, y = date
            window['INPUT 2'].update(f'{y:0>4d}-{m:0>2d}-{d:0>2d}')

window.close()

Upvotes: 2

Related Questions