Sir
Sir, my program is functioning correctly, but when I click the button in the grid that executes the function and displays the result in the last cell, we require the result to appear in the first cell. Additionally, we need to ensure that the first column is focused. Could you please provide guidance on how to achieve this? Thank you.
import tkinter as tk
import pandas as pd
from tkinter import *
global mrowid
def print_value1(entry,row, col):
entry.delete(0, END)
entry.insert(0,'testing data')
entry.focus()
myStringVar.set(row)
def tcompile():
masterlines = []
i=1
for i in range(total_rows1):
row = []
j=2
for j in range(total_columns):
data = my_entries[i*total_columns+j].get()
# data = int(data) # Removed for testing purposes
row.append(data)
masterlines.append(row)
print(masterlines)
df = pd.DataFrame(masterlines)
df.columns =['Name', 'Code', 'Age', 'Weight','testmfa']
df = df.fillna(0)
root = tk.Tk()
total_rows = 5
total_rows1 = 5
total_columns =5
my_entries = []
for i in range(total_rows):
tk.Label(root, text='aaaaa11').grid(row=0, column=0)
tk.Label(root, text='aaaaa22').grid(row=0, column=1)
tk.Label(root, text='aaaaa33').grid(row=0, column=2)
tk.Label(root, text='aaaaa44').grid(row=0, column=3)
tk.Label(root, text='aaaaa555').grid(row=0, column=4)
tk.Label(root, text='buttttonnn ').grid(row=0, column=5)
j=1
for j in range(total_columns):
cell = tk.Entry(root)
cell.grid(row=i, column=j)
my_entries.append(cell)
b = Button(root, text="print value", command= lambda entry=cell,i=i,j=j: print_value1(entry,i,j), width=5)
b.grid(row=i, column=j+1)
button = tk.Button(root, text="Click me", command=tcompile)
button.grid(row=20, columnspan=total_columns)
myStringVar = StringVar()
ent4 = tk.Entry(root, text="", textvariable=myStringVar , width=10)
ent4.grid(row=20, column=0)
root.mainloop()