Taking Values from tkinter input boxes to be used as input variables in another function

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.

New contributor

stanley1O1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật