I am currently working on building a data analysis program for my research, and just trying to make it more user-friendly for the undergrads in my lab.
I am trying to take the user input of several textboxes to be used as variables for reading a csv file and pulling data from it. Essentially I am asking the user “which columns in the csv do you want to pull” and taking that input to pull data from said column.
It currently works if I manually input which headers I need:
def plot_eye_data(eye_data, fig):
fig.clear() # Clear previous plots
ax1 = fig.add_subplot(311)
# Plot Left Eye
ax1.plot(eye_data['Timestamp'], eye_data['LeftGazeX'], label='LGaze X')
ax1.plot(eye_data['Timestamp'], eye_data['LeftGazeY'], label='LGaze Y')
ax1.set_xlabel('Timestamp')
ax1.set_ylabel('Gaze Position')
ax1.set_title('Left Eye Gaze Position')
ax1.legend()
ax1.grid(True)
But I am not sure where I am going wrong when using Tkinter to get inputs.
# graph fxn
def plot_eye_data(eye_data, fig, time, leftx, lefty):
fig.clear() # Clear previous plots
ax1 = fig.add_subplot(311)
# Plot Left Eye
ax1.plot(eye_data[time], eye_data[leftx], label='LGaze X')
ax1.plot(eye_data[time], eye_data[lefty], label='LGaze Y')
ax1.set_xlabel('Timestamp')
ax1.set_ylabel('Gaze Position')
ax1.set_title('Left Eye Gaze Position')
ax1.legend()
ax1.grid(True)
# button fxns
def leftx_name():
global leftx
leftx = LeftX_Head_entry.get()
return leftx
def lefty_name():
global lefty
lefty = LeftY_Head_entry.get()
return lefty
def time_name():
global time
time = Time_Head_Entry.get()
return time
# Initialize the main window
root = tk.Tk()
root.title("Eye Data Classification")
# Left side - Controls, File Input Selection, and Text
# data selection window
data_select = tk.Toplevel(root)
data_select.transient(root)
data_select.maxsize(500, 500)
input_folder_label = tk.Label(data_select, text="Input Folder:")
input_folder_label.grid(row=0, column=0, padx=5, pady=5, sticky="w")
input_folder_entry = tk.Entry(data_select, width=20)
input_folder_entry.grid(row=0, column=1, columnspan= 1, padx=5, pady=5)
tk.Button(data_select, text="Browse", command=browse_input_folder).grid(row=0, column=2, padx=5, pady=5)
LeftX_Head_input = tk.Label(data_select, text="LeftX Header")
LeftX_Head_input.grid(row=1, column=0, padx=5, pady=5, sticky="w")
LeftX_Head_entry = tk.Entry(data_select, width=20)
LeftX_Head_entry.grid(row=1, column=1, columnspan= 2, padx=5, pady=5)
LeftY_Head_input = tk.Label(data_select, text="LeftY Header")
LeftY_Head_input.grid(row=2, column=0, padx=5, pady=5, sticky="w")
LeftY_Head_entry = tk.Entry(data_select, width=20)
LeftY_Head_entry.grid(row=2, column=1, columnspan= 2, padx=5, pady=5)
Time_Head_input = tk.Label(data_select, text="Time Header")
Time_Head_input.grid(row=5, column=0, padx=5, pady=5, sticky="w")
Time_Head_Entry = tk.Entry(data_select, width=20)
Time_Head_Entry.grid(row=5, column=1, columnspan= 2, padx=5, pady=5)
tk.Button(data_select, width = 5, text="Pull Data", command=lambda: [handle_pull_data(), rightx_name(), righty_name(),lefty_name(),leftx_name(),time_name()]).grid(row=6, column=1, pady=5, sticky="ew")
There is other inputs (hence the tkinter window will look yucky)
I was expecting it to be able to grab the contents of said textbox, then use that value in pulling the data from the csvs and graphing it, but it just tells me the variables in the plot_eye_data are undefined. When telling it to print the contents of a textbox it can:
print(leftx)
But won’t use that variable in the graph. However hard-coding that variable:
leftx = LeftEyeX
Correctly grabs the column.
stanley1O1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.