Unnamed Tkinter object reference?

Christopher Myers chris.myers at ingenta.com
Tue May 14 12:44:05 EDT 2002


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.


Case in point:

I'm building a calendar widget (is there one already?), in a Pmw dialog
with Tkinter.Buttons for the days, and I want a click on a button to
change the color of that day to red.
Then, I can use the Pmw.Dialog's command parameter method to check the
dialog for which button is red in order to return the label on the
button, therefore giving me the selected date.

%< --------- snip  -----------

import calendar
self.calendarSelectDialog = Pmw.Dialog(master, title = 'Select Date',
                                       buttons = ('OK', 'Cancel'),
                                       defaultbutton = 'OK', )
           # Not yet implented . . . . command = self.execCalDialog )
self.myCalFrame = Frame(self.calendarSelectDialog.interior())
self.myCalFrame.pack()
#
# Skipped some stuff to remove clutter . . .
#

# Day column Headings
col_cnt=0
for name in calendar.day_name:
    day_abbrev = name[:2]
    Label(self.myCalFrame, text=day_abbrev).grid(row=1, column=col_cnt)
    col_cnt=col_cnt+1

# Buttons for actual days.
mc = calendar.monthcalendar(self.y, self.m)  # <-- This is a cool
method!

for i in range(len(mc)):
    for j in range(7):
        num = mc[i][j]
        if num == 0:
            state="disabled"
            n = ""
        else:
            state="normal"
            n = `num`
        Button(self.myCalFrame, text=n, width=2, state=state,
               command=self.red_day).grid(row=i+2, column=j)
#
# Skip more stuff
#

def red_day(self):
    # How to do this type of thing????
    # i.e. How do I tell Python that the thing I want to configure
    # is the thing that calls this method?
    me.configure(background="red")

%< ----------------------------------------


Thanks in Advance!!


-- 
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