0

我在一个窗口中有一个日历按钮和一个文件浏览器按钮。

从日历中选择日期时,我希望所选日期显示在按钮旁边。当用户选择文件时,我希望在输入框中显示路径。我怎样才能做到这一点?

这是我的代码:

import PySimpleGUI as sg

layout = [[sg.Text('Date to Start Summing')],
          [sg.In(key='-CAL-', visible=False),
           sg.CalendarButton('Calendar', target='-CAL-', pad=None, font=('MS Sans Serif', 10, 'bold'),
                             button_color=('red', 'white'), format='%m/%d/%Y')],
          [sg.Text('Filename')],
          [sg.In(key='-DIR-', visible=False),
           sg.Input(size=(20, None)), sg.FileBrowse('Browse', target='-DIR-')],
          [sg.OK(), sg.Cancel()]]


window = sg.Window('Data Collector', layout, grab_anywhere=False, size=(400, 280), return_keyboard_events=True,
                   finalize=True)

event, values = window.read()
4

1 回答 1

0

工作代码:

import PySimpleGUI as sg

layout = [[sg.Text('Date to Start Summing', key='-CALOUTPUT-', font=('Arial', 10, 'bold')), sg.Text(key='-CAL-', size=(10, None), font=('Arial', 10, 'bold'))],
          [sg.CalendarButton('Calendar', target='-CAL-', pad=None, font=('Arial', 10, 'bold'), format='%m/%d/%Y')],
          [sg.Text('Filename', key='-FOUTPUT-', font=('Arial', 10, 'bold'))],
          [sg.In( visible=False),
           sg.Input(key='-DIR-', size=(20, None), font=('Arial', 10, 'bold')), sg.FileBrowse('Browse', target='-DIR-', font=('Arial', 10, 'bold'))],
          [sg.OK(), sg.Cancel()]]


window = sg.Window('Data Collector', layout, grab_anywhere=False, size=(400, 280), return_keyboard_events=True,
                   finalize=True)

event, values = window.read()
于 2020-02-25T19:55:47.573 回答