Cannot pass the entered variable from a function to a .py script - python

I want to make a GUI, which will take the data date entered by the user and pass it to a python script that would be executed when a button is pressed in the GUI. My code looks like this as of now:
import tkinter as tk
from tkinter.font import Font
from tkinter import *
from tkinter import filedialog, Text
import os
main_gui = tk.Tk()
main_gui.title("Widefield Analysis")
main_gui.geometry("600x500")
datadate = StringVar()
def data_date():
global ddate
ddate = datadate.get()
ddate_label.config()
return ddate
def image_files(ddate):
global varlist1
from Image_files import filepath, filepath2, list1, filelist2
varlist1 = [filepath, filepath2, list1, filelist2]
return varlist1
ddate_label = Label(main_gui, text='Enter Data Date', font='Ariel 13 bold')
ddate_label.pack()
ddate_label.place(x=20, y=13)
date = tk.Entry(main_gui, textvariable=datadate, font='Ariel 13 normal', width=10)
date.place(x=205, y=10)
button1 = tk.Button(main_gui, text="Done", font="Ariel 13 bold", command=lambda:[data_date(), image_files(ddate)])
button1.place(x=500, y=450)
main_gui.mainloop()
The main idea is to take the datadate entered by the user and feed it to the Image_files.py script (which is a part of the image_files function, that gets executed when the "Done" button gets pressed). From the Image_files.py script, I need to return these variables: filepath, filepath2, list1, filelist2, which will later be used for other scripts being run in the same GUI. I am unable to do it now and need help.
I'm providing the code for the Image_files.py script here as well:
#THIS CODE PRECEEDS THE Image_stack.py CODE
import os
#datadate = input("Enter data date: ")
datadate = "17032020"
filepath = ("/home/abhra/Documents/My_first_code/" + datadate)
os.chdir(filepath)
#print("Current Working Directory ", os.getcwd()) **TO KNOW WHAT IS THE CURRENT WORKING DIRECTORY**
filelist = os.listdir()
filecount = 0
#CREATES ARRAY FOR TSERIES FILES
for x in range (0,len(filelist),1):
aa = filelist[x].startswith("TSeries")
if aa == True:
filecount = filecount + 1
list1 = [0] * filecount
counter=0
for y in range (0,len(filelist),1):
bb = filelist[y].startswith("TSeries")
if bb == True:
list1[counter] = filelist[y]
counter = counter+1
del aa, bb, x, y
list1.sort() #good initial sort but doesnt sort numerically very well
sorted(list1) #sort numerically in ascending order
#IMPORT STUFF FROM .mat FILE FROM PP_FILES
filepath2 = ("/home/abhra/Documents/My_first_code/" + datadate + "/" + "PP_FILES")
os.chdir(filepath2)
filelist2 = os.listdir()
filelist2.sort()
sorted(filelist2)
os.chdir("/home/abhra/Documents/My_first_code/")

Related

storing output text in a tkinter textbox

im looking to output a list of text to both a text file as well as a tkinter textbox. Currently I have it working to print to a text file being held in the same folder. I would like this same list to be printed on screen into the outputToScreen textbox
From my research I think I am meant to use .insert(index , text) but I can not get this method to work. I have also seen some old code using a .set function but when I tried this I came across an error saying that textbox's don't have that method
#file -> gui.py
# IMPORT tkinter for GUI creation and import scripts for functions
from tkinter import *
from tkinter.ttk import *
import scripts
import customtkinter
windowDim = str(750)+'x'+str(600)
window = customtkinter.CTk()
window.title("INFO GENERATOR")
window.geometry(windowDim)
window.resizable(True, True)
# Modes: system (default), light, dark
customtkinter.set_appearance_mode("dark")
# Themes: blue (default), dark-blue, green
customtkinter.set_default_color_theme("customTkinterTheme.json")
outputToScreen = customtkinter.CTkTextbox(window , width=400 , height=200)
outputToScreen.place(x=200, y=300)
def popupmsg(msg):
popup = customtkinter.CTk()
popup.title("!")
label = customtkinter.CTkLabel(popup, text=msg,)
label.pack(side="top", fill="x", pady=10)
B1 = customtkinter.CTkButton(popup, text="Okay", command=popup.destroy)
B1.pack()
popup.mainloop()
# create main window
# window specs are 700 x 350 and window is not able to be resizeable
# CREATING USER CONTROLS
# each button will print a list of items (number of items will be come from the entry userValue)
userEntry = customtkinter.CTkEntry(window)
# userValue = int(userValue)
userValue = ""
userEntry.place(x=325, y=200)
userEntry.insert(0, userValue)
userValueLabel = customtkinter.CTkLabel(
window, text="ENTER AMOUNT OF RECORDS YOU WOULD LIKE").place(x=275, y=170)
label = customtkinter.CTkLabel(window, text="INFOMATION GENERATOR by Noah Mackay "
).pack()
def outputEmails(userValue):
# function receives the amount of records the user wants to print
# function will be called when email button is clicked
# this function will clear the output file and then read open it
# will call the generateEmail function from scripts.py file
# outputs the amount of records based on the user input in the entry text box
userValue = int(userEntry.get())
outputFile = scripts.generateEmail(userValue)
file = open('output.txt', 'w').close()
file = open('output.txt', 'w')
file.write(str(outputFile))
outputToScreen.set(outputFile)
popupmsg("PRINTING WORKED")
def outputNames(userValue):
# function receives the amount of records the user wants to print
# function will be called when email button is clicked
# this function will clear the output file and then read open it
# will call the generateEmail function from scripts.py file
# outputs the amount of records based on the user input in the entry text box
userValue = int(userEntry.get())
outputFile = scripts.generateName(userValue)
file = open('output.txt', 'w').close()
file = open('output.txt', 'w')
file.write(str(outputFile))
outputToScreen.set(outputFile)
popupmsg("PRINTING COMPLETED")
def outputCost(userValue):
userValue = int(userEntry.get())
outputFile = scripts.generateCost(userValue)
file = open('output.txt', 'w').close()
file = open('output.txt', 'w')
file.write(str(outputFile))
outputToScreen.set(outputFile)
popupmsg("PRINTING COMPLETED")
def outputProduct(userValue):
userValue = int(userEntry.get())
outputFile = scripts.generateProduct(userValue)
file = open('output.txt', 'w').close()
file = open('output.txt', 'w')
file.write(str(outputFile))
outputToScreen.set(outputFile)
popupmsg("PRINTING COMPLETED")
def outputPhoneNumber(userValue):
userValue = int(userEntry.get())
outputFile = scripts.generatePhoneNumber(userValue)
file = open('output.txt', 'w').close()
file = open('output.txt', 'w')
file.write(str(outputFile))
outputToScreen.insert(0,outputFile)
popupmsg("PRINTING COMPLETED")
# creates 5 buttons each have their respective output function attached using command=
emailButton = customtkinter.CTkButton(window, text="EMAILS",
command=lambda: outputEmails(userValue)).place(x=5, y=40)
productButton = customtkinter.CTkButton(window, text="PRODUCTS",
command=lambda: outputProduct(userValue)).place(x=150, y=40)
phoneNumberButton = customtkinter.CTkButton(
window, text="PHONE NUMBERS" , command= lambda:outputPhoneNumber(userValue)).place(x=300, y=40)
costButton = customtkinter.CTkButton(window, text="PRICES",
command=lambda: outputCost(userValue)).place(x=450, y=40)
nameButton = customtkinter.CTkButton(
window, text="FIRST + LAST NAMES", command=lambda: outputNames(userValue)).place(x=600, y=40)
window.mainloop()
#file -> scripts.py
import random
def generateName(numberOfItemsNeed):
# opens 2 files. One containing first names and the other containing last names
firstNameFile = open('dataFiles\FirstNamesData.txt', 'r')
lastNameFile = open('dataFiles\LastNamesData.txt', 'r')
# builds values for the while statement and the return string
returnValue = ""
counter = 0
# builds the return string using a while loop and removing the newline character
# after each line from both files when being read
while counter < int(numberOfItemsNeed):
returnValue += str(firstNameFile.readline().strip("\n")
) + " " + str(lastNameFile.readline().strip("\n")) + "\n"
counter = counter + 1
# returns a list of "human" names in a single string divided by a newline character
return (returnValue)
def generateEmail(numberOfItemsNeed):
# opens a file containing a records of first names
firstNameFile = open('dataFiles\dictonary.txt', 'r')
counter = 0
# A list of commonly used email address suffixs
suffix = ['#gmail.com', '#gmail.ca', '#hotmail.com',
'#hotmail.ca', '#mail.com ', '#mail.ca', '#gov.ca']
returnValue = ""
while counter < int(numberOfItemsNeed):
returnValue += firstNameFile.readline().strip("\n") + \
str((random.randrange(0, 100))) + \
suffix[random.randrange(0, len(suffix))]+'\n'
counter = counter + 1
return (returnValue)
def generateCost(numberOfItemsNeed):
# generates a random item price in the inclusive range of 0.00$ to 1000.99$
counter = 0
cost = ""
while counter < int(numberOfItemsNeed):
cost += '$' + str(random.randrange(0, 1000)) + \
"." + str(random.randrange(0, 99)) + '\n'
counter = counter+1
return cost
def generateProduct(numberOfItemsNeed):
counter = 0
returnValue = ""
productList = open('dataFiles\itemData.txt', 'r')
while counter < int(numberOfItemsNeed):
returnValue += str(productList.readline()
).strip("\n") + str(generateCost(1))
counter = counter + 1
return (returnValue)
def generatePhoneNumber(numberOfItemsNeed):
counter = 0
returnValue = ""
while counter < int(numberOfItemsNeed):
firstNumber = str(random.randrange(100, 999))
secondNumber = str(random.randrange(1000, 9999))
thirdNumber = str(random.randrange(100, 999))
returnValue += firstNumber + "-" + secondNumber + "-" + thirdNumber + '\n'
counter = counter + 1
return (returnValue)
def shuffleFile(filePath):
lines = open(filePath).readlines()
random.shuffle(lines)
open(filePath, 'w').writelines(lines)
# shuffleFile('dataFiles\dictonary.txt')
Text widget indexes are strings of the form line.character with lines starting at 0 and characters starting at 1. So, to insert at the start you need to use the index "1.0", not 0. If you want to insert at the end you can use the special index "end". If the widget is empty, "1.0" and "end" yield identical results.
outputToScreen.insert("1.0", outputToFile)

Getting each list in matplotlib to be its own row within an eventplot

So basically here is the problem I've set out to solve. I have data that I want to graphically show for a paper. Basically, the data is organized into trials. Each trial has a tone and then positive vocalizations are measured. I've normalized the graph to the onset of the tone and the tone is 10 seconds long. The graph I have as far as the x axis is concerned is accurate. My problem lies in the y axis. I've basically created one main list as the data and then created a for loop to add each trial group of vocalizations in as its own list. Now my problem is that I want each trial to have a corresponding value on the y axis. There are sixty trials so ideally there should be a value of sixty on the y axis, and I should end up with each y value corresponding to a trial set. For some reason my graph isn't quite working like that. Here is my code
#%%imports and setup for initial data
import matplotlib.pyplot as plt
import numpy as np
import tkinter as tk
from tkinter import *
from tkinter import filedialog
import pandas as pds
from tqdm import tqdm as tq
from pathlib import Path
import seaborn as sns
#%%Create Button Function for data input
def get_file_path():
global file_path
# Open and return file path
file_path= filedialog.askopenfilename(title = "Select A File", filetypes = (("Excel Files", "*.xlsx"),))
l1 = Label(window, text = "File path: " + file_path).pack()
window = Tk()
width = window.winfo_screenwidth()
height = window.winfo_screenheight()
def close():
window.destroy()
# Creating a button to search the file
b1 = Button(window, text = "Open File", command = get_file_path).pack()
b2 = Button(window, text = "OK", command = close).pack()
window.geometry("%dx%d" % (width, height))
window.mainloop()
print(file_path)
#%%Read Excel File
ds = pds.read_excel(io = file_path, usecols = "A,D", skiprows = 1, keep_default_na = False)
#%%usv incident beggining times in seconds
usvTimes = ds["Begin Time (s)"].tolist()
#beginning times for tones in seconds
toneStart = ds["Tone Time Markers"].tolist()
toneStart2 = ds["Tone Time Markers"].tolist()
#%%creates empty lists to be used by loops later
graphStart = []
graphEnd = []
#%%creates the first parameter of the x value for each graph
print("Calculating GraphStart")
for num in tq(toneStart):
try:
int(float(num))
except:
pass
else:
graphStart.append(num - 10)
print("Complete")
#%%creates the second parameter of the x value for each graph
print("Calculating GraphEnd")
for num in tq(toneStart2):
try:
int(float(num))
except:
pass
else:
graphEnd.append(num + 10)
print("Complete")
#%%Makes usvTimes usable
print("Calculating USVTimeStamps")
for num in tq(usvTimes):
try:
int(float(num))
except:
pass
print("Complete")
#%%pair beggining and end parameter into a full list
graphpair = zip(graphStart,graphEnd)
#%%Zip x and y coordinates together
graphx = list(graphpair)
#%%create graphs
print("Input File Name:")
filename = str(input())
print("Creating Graphs")
myPath = str(Path.home() / "Downloads")
print(myPath)
lists = []
for index, num in tq(enumerate(graphx)):
x,y = num
leftbound = (x - x) - 30
rightbound = y - x
za = x - 10
zb = x + 10
sublist = []
for i in usvTimes:
try:
x + 0
except:
pass
if i == 0:
continue
elif za <= i <= zb:
sublist.append(i-x)
else:
continue
lists.append(sublist)
print(lists)
data = lists
plt.eventplot(data , colors='black' , lineoffsets=1 , linelengths=1)
plt.ylabel("Trial Number")
plt.xlabel("Time of USV Incidence Normalized to tone")
plt.savefig(myPath + "/Eventplot" + filename + str(num) + ".pdf")
plt.show()
print("Graphs Complete")

Plotted Images in Matplotlib Continue to get smaller, Final pdf doesn't show all plots

I'm trying to get multiple plots into a single figure. Having them in one column has been the approach I have been using but it isn't necessary. The problem I've been running into is that my figures will graph and each figure will be slightly smaller than the previous one. Additionally, the pdf I save from the figure is oddly proportioned and doesn't show all of the subplots. My commenting is slightly funky because I've been testing and cobbling from some of my old projects as well as the internet so don't look into it too much.
Here is my full code:
import matplotlib.pyplot as plt
import numpy as np
import tkinter as tk
from tkinter import *
from tkinter import filedialog
import pandas as pds
from tqdm import tqdm as tq
from pathlib import Path
#%%Create Button Function for data input
def get_file_path():
global file_path
# Open and return file path
file_path= filedialog.askopenfilename(title = "Select A File", filetypes = (("Excel Files", "*.xlsx"),))
l1 = Label(window, text = "File path: " + file_path).pack()
window = Tk()
width = window.winfo_screenwidth()
height = window.winfo_screenheight()
def close():
window.destroy()
# Creating a button to search the file
b1 = Button(window, text = "Open File", command = get_file_path).pack()
b2 = Button(window, text = "OK", command = close).pack()
window.geometry("%dx%d" % (width, height))
window.mainloop()
print(file_path)
#%%Read Excel File
ds = pds.read_excel(io = file_path, usecols = "A,D", skiprows = 1, keep_default_na = False)
#%%usv incident beggining times in seconds
usvTimes = ds["Begin Time (s)"].tolist()
#beginning times for tones in seconds
toneStart = ds["Tone Time Markers"].tolist()
toneStart2 = ds["Tone Time Markers"].tolist()
#%%creates empty lists to be used by loops later
graphStart = []
graphEnd = []
#%%creates the first parameter of the x value for each graph
print("Calculating GraphStart")
for num in tq(toneStart):
try:
int(float(num))
except:
pass
else:
graphStart.append(num - 30)
print("Complete")
#%%creates the second parameter of the x value for each graph
print("Calculating GraphEnd")
for num in tq(toneStart2):
try:
int(float(num))
except:
pass
else:
graphEnd.append(num + 30)
print("Complete")
#%%Makes usvTimes usable
print("Calculating USVTimeStamps")
for num in tq(usvTimes):
try:
int(float(num))
except:
pass
print("Complete")
#%%pair beggining and end parameter into a full list
graphpair = zip(graphStart,graphEnd)
#%%Zip x and y coordinates together
graphx = list(graphpair)
#%%create graphs
print("Creating Graphs")
myPath = str(Path.home() / "Downloads")
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
for index, num in tq(enumerate(graphx)):
x,y = num
leftbound = x
rightbound = y
graphnum = index + 1
a = []
for x in usvTimes:
try:
x + 0
except:
pass
else:
if leftbound <= x <= rightbound:
a.append(x)
plt.figure()
plt.subplot(graphnum,1,graphnum)
plt.hlines(1, leftbound, rightbound)
plt.eventplot(a, orientation='horizontal', colors='b')
plt.xlabel("Time in Recording (s)")
plt.ylabel("Arbitrary Axis (Abu)")
else:
pass
plt.savefig(myPath + "/Eventplot" + ".pdf")
print("Graphs Complete")

Return a user event function value as a string in Python before the code is compiled

I have a drag and drop GUI function that displays the filename and gives the file pathway. I am trying to plug that file path into Pandas to manipulate later down the road. My issue is that python trys to open the path way before the user can drop the file into the function. How do I tell it to wait until the user enters the data before it compiles. Below is the code that I am using and have narrowed it down to what I think is the problem. Bonus points if you can tell me how to turn the function into a class so that I dont have to edit the function per entry box.
import pandas as pd
import numpy as np
import docx
import os
import zipfile
import re
import PyPDF2
from docx2pdf import convert
import csv
from math import *
from pathlib import Path
import statistics
import matplotlib.pyplot as plt
from scipy.stats import linregress, stats
from tkinter import *
from tkinterdnd2 import *
from docx2pdf import convert
root = TkinterDnD.Tk()
root.title('Pathfinder')
root.geometry('600x400')
root.config(bg='#039dfc')
def drop(event):
var.set(event.data)
stringvar = str(event.data)
size = len(stringvar)
res = [] # list of file paths
name = ""
idx = 0
while idx < size:
if stringvar[idx] == "{":
j = idx + 1
while stringvar[j] != "}":
name += stringvar[j]
j += 1
res.append(name)
name = ""
idx = j
elif stringvar[idx] == " " and name != "":
res.append(name)
name = ""
elif stringvar[idx] != " ":
name += stringvar[idx]
idx += 1
if name != "":
res.append(name)
file_paths = res
current_e_box_item = set(e_box.get())
for file_path in file_paths:
if file_path.endswith(".XLS"):
path_object = Path(file_path)
file_name = path_object.name
if file_name not in current_e_box_item:
e_box.insert("end", file_name)
e_box.delete(0,last=size)
print(file_name)
print (res)
print(file_path)
print(path_object)
print(stringvar)
return file_path # this is what i want
var = StringVar()
e_box = Entry(root, textvar=var)
e_box.place(x=150, y=90, width=180, height=25)
e_box.drop_target_register(DND_FILES)
e_box.dnd_bind('<<Drop>>', drop)
File_as_DF = pd.read_excel(file_path) # This is where it needs to go
def drop2(event):
var2.set(event.data)
stringvar2 = str(event.data)
print (stringvar2)
var2 = StringVar()
e_box2 = Entry(root, textvar=var2)
e_box2.place(x=150, y=150, width=180, height=25)
e_box2.drop_target_register(DND_FILES)
e_box2.dnd_bind('<<Drop>>', drop2)
def drop3(event):
var3.set(event.data)
stringvar3 = str(event.data)
print(stringvar3)
var3 = StringVar()
e_box3 = Entry(root, textvar=var3)
e_box3.place(x=150, y=200, width=180, height=25)
e_box3.drop_target_register(DND_FILES)
e_box3.dnd_bind('<<Drop>>', drop3)
root.mainloop()
To answer the main question -- you need this:
File_as_DF = pd.read_excel(file_path) # This is where it needs to go
to happen after your drop(), not before it. Presumably you have a plan for what you want to do with that dataframe -- your drop() function should kick off a function that does that thing.
For the bonus points, instead of classes, I'd just have a function that builds a box along with its own drop function:
def drop2(event):
var2.set(event.data)
stringvar2 = str(event.data)
print (stringvar2)
var2 = StringVar()
e_box2 = Entry(root, textvar=var2)
e_box2.place(x=150, y=150, width=180, height=25)
e_box2.drop_target_register(DND_FILES)
e_box2.dnd_bind('<<Drop>>', drop2)
def drop3(event):
var3.set(event.data)
stringvar3 = str(event.data)
print(stringvar3)
var3 = StringVar()
e_box3 = Entry(root, textvar=var3)
e_box3.place(x=150, y=200, width=180, height=25)
e_box3.drop_target_register(DND_FILES)
e_box3.dnd_bind('<<Drop>>', drop3)
becomes:
def make_e_box():
var = StringVar()
def drop(event):
var.set(event.data)
print(event.data)
e_box = Entry(root, textvar=var)
e_box.drop_target_register(DND_FILES)
e_box.dnd_bind('<<Drop>>', drop)
return e_box
make_e_box().place(x=150, y=150, width=180, height=25)
make_e_box().place(x=150, y=200, width=180, height=25)

Python Tkinter return self.func(*args) and TypeError:list indices must be integers or slices, not str

The goal is to extract excel data and write it to a text file, based on an input through tkinter. The Tkinter box is popping up, but when the entry input is given, it produces an error in the terminal.
I have tried changing the line 30 int or float.
Thank you for any help you can give.
The code below is creating this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\bob\AppData\Local\Programs\Python\Python37-
32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "c:/Users/bob/Dropbox/Financial/PERSONAL FINANCES/budget.py",
line 30, in click
result = np.array(sheet.cell_value(i,budget_col))
File "C:\Users\bob\AppData\Local\Programs\Python\Python37-
32\lib\site-packages\xlrd\sheet.py", line 419, in cell_value
return self._cell_values[rowx][colx]
TypeError: list indices must be integers or slices, not str
My code:
import os
from tkinter import *
import time
import xlrd
import numpy as np
os.system('cls' if os.name == 'nt' else 'clear')
def click():
file_location = 'C:/Users/bob/Dropbox/Financial/PERSONAL FINANCES/NEW DOUBLE ENTRY PERSONAL.xlsx'
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(6)
budget_col = textentry.get()
excel_col1 = np.array([])
array_length = sheet.nrows
for i in range(array_length):
result = np.array(sheet.cell_value(i,0))
excel_col1 = np.append(excel_col1,[result])
excel_col2 = np.array([])
for i in range(array_length): # 0 to total rows
result = np.array(sheet.cell_value(i,1))
excel_col2 = np.append(excel_col2,[result])
excel_col_bud_col = np.array([])
for i in range(array_length): # 0 to total rows
result = np.array(sheet.cell_value(i,budget_col))
excel_col_bud_col = np.append(excel_col_bud_col,[result])
#Writing text file to desktop
# CREATING THE textfile:
created_name = '\curr_budget.txt'
if os.name == 'nt':
desktop = str(os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop'))
query_if_windows = "windows"
else:
desktop = str(os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop'))
query_if_windows = "not windows"
filename = desktop + created_name
text_file = open(filename,"w")
text_file.write(time.strftime("%c\n"))
text_file.write("\n")
text_file.write('Accounts - Budget\n')
text_file.write("\n")
for n in range(4,sheet.nrows-2):
x = excel_col_bud_col[n]
y = excel_col2[n]
z = excel_col1[n]
text_file.write(z + " " + x + " " + y)#,"{bud:8.8} {name}".format(name=y,bud=x))
text_file.write("\n")
text_file.write("\n")
text_file.write('Note, some debit card transactions will take a few days so will not appear above\n')
text_file.close()
window = Tk()
window.title("Print Budget to Desktop")
window.configure(background="white")
Label (window,text="Enter column across, starting at 0, where this month's budget is located", bg="white", fg = "black", font="none 12 bold") .grid(row=0, column=0, sticky=W)
textentry = Entry(window, width=20,bg="white") #column '15' for August budget (starts at 0)
textentry.grid(row=1,column=0,sticky=W)
Button(window, text="Print Budget to Desktop",width=23,command=click) .grid(row=2,column=0,sticky=W)
window.mainloop()
The error telling you precisely what the problem is. It is saying you need to pass an integer rather than a string to a particular function. That is happening because of these two lines:
budget_col = textentry.get()
...
result = np.array(sheet.cell_value(i,budget_col))
budget_col is a string, but sheet.cell_value requires an integer. You need to convert the value you get from textentry.get() to an integer before you can pass it to that function.

Categories