The "real" name

André andre.roberge at gmail.com
Sat Jan 21 16:23:59 EST 2006


engsolnorm at hotmail.com wrote:
> I'm playing with a sudoku GUI...just to learn more about python.
>
> I've made 81 'cells'...actually small canvases
>
> Part of my scheme to write the cells (all 81 of them in the gui) to a file (using the the SAVE callback/button), then
> restore the gui cells from the contents of the saved file, which depends on knowing the "name" of the cell with the
> focus, or one (or more) which have a number.
>
> The print shows .9919624.9990312, but this nunber (name?) does not work in:
>
> cell-name of cell-.create_text(18,18, text = somevar, fill = 'blue' , font = ('arial', 18, 'bold'))
>
> Also, how can I declare a variable outside of the mainloop/callback scheme which would be 'known' to the callbacks?
>
> Thanks,
> Norm
How about using a dict, something like (untested):
cells = {}
for row in range(1, 10):
.   for column in range(1, 10):
.      cells[(row, column)] = canvas()  # or whatever you use to create
a canvas

Then, to put a value in a given cell, you simply to
cell[(row, column)].create_text(...)

André




More information about the Python-list mailing list