我不希望将时间记录在输入框或数据库中。我是PySimpleGUI的新手,这是我第一次使用它。
import PySimpleGUI as sg
import datetime
main_name_list = ['Joe',
'Billy',
'Jerry',
'Tommy',
'Bobby',
'Oscar']
main_reason_list = ['Vacation',
'Training',
'Work Travel',
'FMLA',
'Development',
'Other']
name = main_name_list
reason = main_reason_list
# Stuff inside window
layout = [
[sg.Text('Scheduler')],
[sg.Combo(name, size=(30,4), enable_events=True)],
[sg.Combo(reason, size=(30,4), enable_events=True)],
[sg.T('Start Date')],
[sg.In('', size=(20,1), key='input1')],
[sg.CalendarButton('Choose Start Date', target='input1', key='date1')],
[sg.T('End Date')],
[sg.In('', size=(20,1), key='input2')],
[sg.CalendarButton('Choose End Date', target='input2', key='date2')],
[sg.Button('Submit'), sg.Button('Exit')]]
# create the window
window = sg.Window('Scheduler',grab_anywhere=False).Layout(layout)
# event loop to process events and get the values of inputs
while True:
event, values = window.Read()
print(event, values)
if event in (None, 'Exit'):
break
window.Close()
我继续获取与日期相关的时间。
答案 0 :(得分:2)
您可以为datetime
(http://strftime.org)设置格式
sg.CalendarButton(..., format='%Y:%m:%d')
有关更多选项,请参见source code。