简体   繁体   中英

I want to use User input from PySimpleGUI to one of my output Excel file name

I wanted to use User input from PYSimpleGUI to one of my output Excel file name in Python. I am getting error:

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)**

I want output file name as userinput _Data_with_Flags

Please do correct if my code is wrong.

使用 sg.Text(key="-IN4-") 更改元素行,如下所示:

[sg.T("")],   [sg.Text("PID:             "), sg.Input(key="-IN4-")],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM