canvas.create_window: access the window via the canvas?

Anna M. am at mtix.de
Tue May 29 17:02:54 EDT 2001


Hello, it's the first time I'm here and I hope that somebody can help
me...

Working on a multicolumn-list-widget I put a lot of Entry-widgets on a
canvas and store the references to the Canvas windows in a matrix. So
I can easily change a "column" width (and move the other widgets
accordingly etc.)

But I just don't find out how to access the Entry widgets itself
without putting them in an extra matrix:

def createWidgets(self, numrow, numcol):
    self.canv = Canvas(self, width="4i", height="4i")
    rowy = 10
    for i in range(numrow):
        cols = []
        colx = 10
        for j in range(numcol):
            widget = Entry(self.canv, wrap=None, 
                     name = "%d-%d" % (i,j))
            cw = self.canv.create_window(colx, rowy,
                    window=widget, width=50, height=16, 
                    anchor=NW)
            cols.append(cw)
            colx += self.colwidth
        self.rows.append(cols)
        rowy += self.rowheight

    self.canv.pack()


Then I want to use something like:

    w = self.canv.itemcget(self.rows[0][0], 'window')
    w.configure(bg="blue")

But this doesn't work.

When I just print w, I get: .8407612.8409116.0-0  which looks pretty
good to me, but w.configure (or even w.__dict__) raises an attribute
error.

Is there a way to access the Entry widget via the Canvas window ID? 

Thanx a lot,
Anna



More information about the Python-list mailing list