我希望标签 2 显示所有现有预订的表格。
我尝试将数据框设为字符串,然后设为列表。
import pandas as pd
from pandas import DataFrame
#create dataframe to simulate databse with names and dates
data = {'Name': ['Joe Smith', 'Jason Leary','Bill Murray'],
'Start Date': ['2019/10/01', '2019/11/01','2019/12/01'],
'End Date': ['2019/10/15', '2019/11/15','2019/12/15']
}
df = pd.DataFrame (data, columns = ['Name','Start Date','End Date'])
Data_Table = df.to_string()
# Stuff inside window
tab1_layout = [
[sg.Text('The 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=(10,1), key='input1')],
[sg.CalendarButton('Choose Start Date', target='input1', key='date1',format='%Y/%m/%d')],
[sg.T('End Date')],
[sg.In('', size=(10,1), key='input2')],
[sg.CalendarButton('Choose End Date', target='input2', key='date2', format='%Y/%m/%d')],
[sg.Button('Submit')]]
# create a table to show names and dates with an export to CSV button
tab2_layout = [[sg.Table(values=Data_Table, max_col_width=25, background_color='lightblue',
auto_size_columns=True, justification='right', alternating_row_color='blue', key='_table_')],
[sg.Button('Update')]]
tab3_layout = [[sg.T('This is inside tab 3')],
[sg.In(key='_in3_')]]
# create the window
layout = [[sg.TabGroup([[sg.Tab('Scheduler', tab1_layout, key='_mykey_'),
sg.Tab('Schedule', tab2_layout),
sg.Tab('Admin', tab3_layout)]],
key='_group2_', title_color='darkgrey',
selected_title_color='black', tab_location='topleft')]]
window = sg.Window('My window with tabs', default_element_size=(30,1)).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
if event == 'Update':
window.FindElement('_table_').Update( row_colors=((8,'white', 'red'), (9,'black')))
window.Close()
我希望在选项卡 2 上显示一个带有现有预订的表格。最终这将来自一个数据库,但现在我已经创建了一个 pd.DataFrame。
错误是 TclError: Invalid column index
但我尝试过字符串和列表。