Я пытаюсь взять пользовательский ввод нескольких текстовых полей, которые будут использоваться в качестве переменных для чтения файла csv и извлечения из него данных. По сути, я спрашиваю пользователя «какие столбцы в CSV-файле вы хотите получить» и принимаю этот ввод для извлечения данных из указанного столбца.
В настоящее время это работает, если я вручную ввожу, какие заголовки я хочу получить. нужно:
Код: Выделить всё
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)
Код: Выделить всё
# 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")
Я ожидал, что он сможет получить содержимое указанного текстового поля, затем используйте это значение для извлечения данных из CSV и построения графиков, но это просто говорит мне, что переменные вplot_eye_data не определены. При указании распечатать содержимое текстового поля он может:
Код: Выделить всё
print(leftx)
Код: Выделить всё
leftx = LeftEyeX
Обновление:
Вот функция для вызова графиков.
Код: Выделить всё
def handle_pull_data():
global current_file_path, eye_data, input_files
if input_files:
file = input_files.pop(0)
current_file_path = os.path.join(input_folder_entry.get(), file)
eye_data = read_eye_data(current_file_path)
update_plots()
else:
current_file_path = "" # No more files to process
update_folder_counters()
def update_plots():
if current_file_path:
plot_eye_data(eye_data, fig, leftx, lefty, rightx, righty)
plot_canvas.draw()
Подробнее здесь: https://stackoverflow.com/questions/786 ... in-another