Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PythonTkinter使用变量和来自GUI的用户输入来运行代码_Python_Pandas_File_Tkinter - Fatal编程技术网

PythonTkinter使用变量和来自GUI的用户输入来运行代码

PythonTkinter使用变量和来自GUI的用户输入来运行代码,python,pandas,file,tkinter,Python,Pandas,File,Tkinter,我试图提取我放入文本框中的信息并运行以下代码,我想指定我希望程序读取的csv文件,并从该文件中找到我指定的值。我试图在我的pandas阅读器的文本框中硬编码,但在将我在GUI中键入的字符串信息外推并显示该字符串以便它可以运行我的代码时遇到了问题。我不确定我是否正确地表达了我的问题。当我运行此命令时,我会得到一个错误: from tkinter import * import pandas as pd def retrieve_input(): file = textBox.get("1

我试图提取我放入文本框中的信息并运行以下代码,我想指定我希望程序读取的csv文件,并从该文件中找到我指定的值。我试图在我的pandas阅读器的文本框中硬编码,但在将我在GUI中键入的字符串信息外推并显示该字符串以便它可以运行我的代码时遇到了问题。我不确定我是否正确地表达了我的问题。当我运行此命令时,我会得到一个错误:

from tkinter import *
import pandas as pd

def retrieve_input():
    file = textBox.get("1.0","end-1c")
    basefileread = pd.read_csv(str(textBox) + '.csv', encoding='latin-1')
    basefilevalue = basefileread.loc[basefileread['Customer'].str.contains('Lam DepT', na=False),'Jun-18\nQty']


master = Tk()
master.geometry('200x100')

textBox = Text(master, height=2, width=10)
textBox.pack()

button1 = Button(master,text="Get Value", command=lambda: retrieve_input())
button1.pack()

master.mainloop()

print(int(textBox)+10)

问题在于
retriece input()
函数
将文本检索到变量
文件中
,然后使用
str(textBox)
读取文件

解决方案应该是这样的

 FileNotFoundError: File b'.!text.csv' does not exist

您需要将pandas代码移动到retrve_输入函数中,以便在单击按钮时运行它。该函数还需要对数据执行任何操作,我假设将其打印或添加到小部件以显示。@好的,谢谢,但是我以前尝试过,现在在编辑的问题中出现了错误,所以我认为这样做是错误的。知道我为什么会出现此错误吗?是否要将保存的名称加载到变量“file”中。所以
basefileread=pd.read\u csv(file+'.csv',encoding='latin-1')
。还记得添加打印或其他内容,以便看到结果。不相关,但lambda函数是无用的。只需传递要直接执行的函数
button1=Button(master,text=“Get Value”,command=retrieve\u input)
@Novel它工作得很好!谢谢你的帮助,这意味着很多。哈哈,因果报应的小偷。同时回答的是东西,sry°^
def retrieve_input():
    file = textBox.get("1.0","end-1c")
    basefileread = pd.read_csv(file +'.csv', encoding='latin-1')
    basefilevalue = basefileread.loc[basefileread['Customer'].str.contains('Lam DepT', na=False),'Jun-18\nQty'