1

I am trying to build GUI using tkinter for displaying csv file data and trying to add few columns which has manual entries,

But I am stuck at how to use StringVar for multiple entries and use trace method to apply changes when user update some value.

I tried to do many things using examples I found online but did not abel to do it.

I am able to create multiple stringvar but can't update it's value and when user enter something in entry widget and also I want to trace those stringvar object,

here is the code I wrote,

import pandas as pd
import tkinter as tk
import numpy as np
from tkinter import ttk

entries = {}

df = pd.read_csv(r'C:\Users\Saurabh\Desktop\Python\New folder\abc.csv')
df['Symbol'].replace('  ', np.nan, inplace=True)
df= df.dropna(subset=['Symbol'])

def search():
    for (name,var) in entries.items():   
        print(f"{name}: {var.get()}")
   

f2 = tk.Tk()

for ind in df.index:
    var = tk.StringVar()
    entries[ind] = var
    entry = ttk.Entry(f2 ,textvariable = var,width=25).grid(row=ind,column=2)

   
but = ttk.Button(f2,text="search",command=search())
but.grid(row=0,column=3)

f2.mainloop()

kindly help

saurabh
  • 23
  • 6
  • 1
    It doesn't look like you're even trying to trace the updates to the variables. Have you tried using the `trace` methods? – Bryan Oakley Jan 02 '23 at 18:58
  • hi @Bryan I did try it , tried many things by seeing lot of posts but not abel to figure it out an I am able to do it for one row but when it comes to multiple rows and entries I am just going blank and all those posts helped me but still stuck at here – saurabh Jan 02 '23 at 19:23
  • thanks @toyota it worked. it was such a dumb mistake. :/ couldn't found it for one week. – saurabh Jan 03 '23 at 04:42

1 Answers1

0

Remove brace bracket.

Change this:

but = ttk.Button(f2,text="search",command=search())

to:

 but = ttk.Button(f2,text="search",command=search) 
toyota Supra
  • 3,181
  • 4
  • 15
  • 19