Dears,
I am looking for a PysimpleGUI way to create dropdown menus which includes range of dates ( only years) , instead of writting the whole list in sg.combo () function or instaed of Choosing Sg.CalendarButton, which are both not useful in my case :
I want something like the below :
import PySimpleGui as sg
sg.Combo([range(Date1 To Date2)], size=(6, 1), font=("Helvetica", 10), key='Dates'),)
Thanks in advance
CodePudding user response:
[range(Date1 To Date2)]
is a list
with only one item which is is a class of immutable iterable objects.
Example Code
import datetime
import PySimpleGUI as sg
def date(year, month=1, day=1):
return datetime.date(year, month=month, day=day)
def get_years(start, stop):
return list(range(start.year, stop.year 1))
start = date(2022)
stop = date(2030)
dates = get_years(start, stop)
layout = [[sg.Combo(dates, font=("Helvetica", 10), size=(5, 5), enable_events=True, key='Dates')]]
window = sg.Window('Title', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
item = values['Dates']
print(item, ":", type(item))
window.close()
2024 : <class 'int'>