如何在PySimpleGUI中从日期中删除时间

时间:2019-10-12 05:11:05

标签: python calendar pysimplegui

我不希望将时间记录在输入框或数据库中。我是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()

我继续获取与日期相关的时间。

1 个答案:

答案 0 :(得分:2)

您可以为datetimehttp://strftime.org)设置格式

 sg.CalendarButton(..., format='%Y:%m:%d')

有关更多选项,请参见source code