Tkinter stocke une liste de widgets enfants dans l'attribut children
d'une image. En comparant grid_info()
de tous les enfants, vous pouvez trouver un widget sur une ligne ou une colonne donnée. Voir fonction find_in_grid
de l'exemple suivant:
from Tkinter import *
root = Tk()
def find_in_grid(frame, row, column):
for children in frame.children.values():
info = children.grid_info()
#note that rows and column numbers are stored as string
if info['row'] == str(row) and info['column'] == str(column):
return children
return None
#create an array of button
width = 10
for i in range(width):
for j in range(width):
b = Button(root, text=str(i*width+j))
b.grid(row=i, column=j)
#Create two entries to set row and column to find. Changing entries print the
#text of the button (and flash it on compatible platforms)
def update(var, value, op):
r = row.get()
c = col.get()
b = find_in_grid(root, r, c)
if b:
print "button ({0},{1}) : {2}".format(r, c, b["text"])
b.flash()
Label(root,text="row:").grid(row=width,column=0)
row = StringVar()
row.trace('w',update)
Entry(root,textvar=row, width=3).grid(row=width,column=1)
Label(root,text="col:").grid(row=width,column=2)
col = StringVar()
col.trace('w',update)
Entry(root,textvar=col, width=3).grid(row=width,column=3)
row.set('3')
col.set('2')
mainloop()
Note: ce petit exemple ne gère pas les widgets couvrant
Pls clarifier, il est difficile de comprendre ce que vous demandez. Vous dites que chaque widget de bouton a un texte et que vous voulez ce texte, et plus tard vous dites que vous voulez des informations sur la grille pas sur le bouton ... – joaquin