我想使用用户输入从PYSimpleGUI到我的输出之一Excel文件名在Python中。我得到错误:
str1 = (sg.Text["-IN4产生绯闻。))TypeError: 'type' object is not subscriptable
import PySimpleGUI as sg
import pandas as pd
import logging
---
---
g.theme("DarkTeal9")
layout = [[sg.T("")], [sg.Text("Data File: "), sg.Input(), sg.FileBrowse(key="-IN1-")],
[sg.T("")], [sg.Text("Output Path: "), sg.Input(), sg.FolderBrowse(key="-IN3-")],
**[sg.T("")], [sg.Text("PID: "), sg.Input(),sg.Text(key="-IN4-")]**,
[[sg.T("")],sg.Button("Submit")]]
---
---
while True:
event, values = window.read()
if (event == sg.WINDOW_CLOSED or event == 'Exit') :
exit()
elif event == "Submit":
print(values["-IN1-"])
print(values["-IN3-"])
loaddata1=pd.read_excel(values["-IN1-"])
**str1=(sg.Text["-IN4-"])**
window.minimize()
break
---
---
---
**loaddata1.to_excel(values["-IN3-"]+" " +f"str1"+"_Data_with_Flags.xlsx", index=0)**
我想输出文件名为userinput_Data_with_Flags
如果我的代码是错误的,请纠正。
用sg.Text(key="-IN4-")改变元素行,如下所示:
[sg.T("")], [sg.Text("PID: "), sg.Input(key="-IN4-")],