Unnamed Tkinter object reference?

Christopher Myers chris.myers at ingenta.com
Thu May 16 14:49:46 EDT 2002


Martin,

Thanks so much!
Combining your code and mine, I(We) have created a very reusable widget,
which would most likely be useful to others in Python-opia.  Any idea if
any of the Tk wrappers out there (Pmw, others?) already have such a
widget?  

Again, many thanks,
Chris

Martin Franklin wrote:
> 
> On Tuesday 14 May 2002 4:44 pm, you wrote:
> > Hello, Python experts!
> >
> > I have an app where I'm building widgets on the fly, and they do not
> > have names, so I can't refer to them to use their methods, but it would
> > be useful to be able to get some sort of temporary handle for a widget
> > to be able to get/set parameters for it.
> >
> 
> Here is one take on it:-
> 
> import calendar, Tkinter
> 
> class TkCalendar(Tkinter.Frame):
>     def __init__(self, parent, year=2002, month=5):
>         Tkinter.Frame.__init__(self, parent)
>         data=calendar.monthcalendar(year, month)
> 
>         col=0
>         for day in calendar.day_abbr:
>             Tkinter.Label(self, text=day).grid(row=0, col=col, sticky='nsew')
>             col+=1
>         row=1
>         for data_row in data:
>             col=0
>             for day in data_row:
>                 if day==0:
>                     col+=1
>                     continue
>                 b=Tkinter.Button(self, text=day, command=lambda self=self,
>                     day=day: self.close(day))
>                 b.grid(row=row, col=col, sticky='nsew')
>                 col+=1
>             row+=1
> 
>         self.pack()
> 
> 
>     def close(self, day):
>         print day
>         self.quit()
> 
> if __name__=='__main__':
>     root=Tkinter.Tk()
>     cal=TkCalendar(root)
>     root.mainloop()
> 
> HTH
> Martin

-- 
Christopher Myers, Graduate Software Developer 
Ingenta, Inc.
12 Bassett St.
Providence, RI  02903
ph:  401.331.2014 x 102
em:  chris.myers at ingenta.com
aim: chrismyers001



More information about the Python-list mailing list