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

I am trying to extract the information that I place into a textbox and run the following code, I want to specify which csv file I want the program to read, and find the value I specified from that file. I tried to hard code in textbox in my pandas reader and am just having trouble extraxting the string information that I type in the GUI and have that string appear so it can run my code. I am unsure if I am articulating my question correctly. And when I run this I get the error:

 FileNotFoundError: File b'.!text.csv' does not exist
12
  • 1
    You need to move the pandas code into the retrive_input function, so it gets run when button is clicked. That function also needs whatever you want to do with the data, I assume print it or add it to a widget for display. Commented Jul 25, 2018 at 20:18
  • @Novel Okay, thank you, however I did try that before and got the error that is posted now in my edited question so I though that was the wrong way to do it. Any idea why I am getting this error? Commented Jul 25, 2018 at 20:33
  • You want to load the name that you saved to the variable "file". So basefileread = pd.read_csv(file+'.csv', encoding='latin-1'). Also remember to add a print or something so you see the result. Commented Jul 25, 2018 at 20:38
  • Unrelated, but that lambda function is useless. Just pass the function to be executed directly. button1 = Button(master,text="Get Value", command=retrieve_input) Commented Jul 25, 2018 at 20:40
  • @Novel It worked perfectly! Thank you for your help, means alot. Commented Jul 25, 2018 at 20:40

1 Answer 1

1

the problem lies within the retriece input() function
you retrieve the text into the variable file, yet use str(textBox) to read the file

solution should work like this

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'
Sign up to request clarification or add additional context in comments.

2 Comments

Lol, karma thief.
Answerong simultaneosly is the stuff, sry °_°^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.