[Tkinter] Changing the text of labels in a grid
Grant Edwards
ge at nowhere.none
Fri Aug 25 10:45:29 EDT 2000
In article <slrn8qcm3f.mk.isard at localhost.localdomain>, Carles Sadurní Anguita wrote:
>Thanks to comp.lang.python's people I've created a grid of labels and I know
>where the user clicked. I want to change the text of the clicked label.
>
>I read that this can be done (for a single label) with
>
>v = StrinVar()
>lbl = Label(master, textvariable=v).grid()
>v.set("hi, folks!")
>
>But, how can I change the text of the label that is in (row, column)? Is it
>possible to do textvariable = v[r][c] (where v is a list of lists)? Python
>complains if I type
>
>v[r][c].set("hi!")
>
>because v is not a StringVar. Can I create a list of lists of StringVars? Is
>there any simpler way?
There are two ways to do this:
1) Creating lists of StringVars, and modify them using the
set() method.
2) Creating lists of Widgets and modify them using using the
"configure" method.
The latter method is demonstrated in
ftp://ftp.visi.com/users/grante/stuff/queens.py
In the queens.py case I'm changing the color and releif of a
label rather than the string, but I think you can see what's
goign on. The grid of widgets is created in Board.__init__(),
and the widgets are changed in Board.placeQueen(), and
Board.removeQueen().
--
Grant Edwards grante Yow! What PROGRAM are
at they watching?
visi.com
More information about the Python-list
mailing list