im working with TKinter to do a excel looklike sheet, so im getting this:
using this code im genereting each column entry:
entriesPI1 = []
for i in range(5,20):
varlayer1pi=tk.StringVar()
b = tk.Entry(newtab1, textvariable=varlayer1pi,background='#87CEEB')
b.grid(row=i, column=6,sticky= 'NSEW')
entriesPI1.append(varlayer1pi)
and changing variables according to columns names and so.
The first part of program does a whole calculation to fill all entries in all columns and rows, and is working fine. But now the next step is to do a 'recalculation', so I will change some values in a row, and do calculation. What i cant reach, is how to simulate the VB command Active.cell
and get the number row, I read i can use .grid_info()
, but how to add in this case to get something like Active entry and get row number. Thanks for your attention and help.
You can use the universal widget method focus_get
to get the widget that has the focus. You can use grid_info
to get the row and column of that widget.
Here's an example, though in production code there needs to be some checking for various conditions (nothing with the focus, the focus is outside the grid, etc)
focused_entry = root.focus_get()
info = focused_entry.grid_info()
row = info['row']
column = info['column']