Pythoncard Multiple components

Lee Harr missive at frontiernet.net
Thu Oct 9 16:32:29 EDT 2003


In article <37152603.0310081227.64731a0f at posting.google.com>, Adrian Smith:
> I am using pythoncard 0.7.2 for windows.
> 
> I am trying to use the same code for a large number of buttons so
> started out by using
> def on_mouseDown(self,event):
>     
> but then I need to display the button that I pressed but you can only
> have an absolute component name like:
>     self.component.Button1.label = "clicked"
> 
> How can I identify the button pressed and still use the same procedure
> to update  the clicked button? I tried self.component.label =
> "clicked" with out the reference to the actual button used?
> 
> Any ideas, especially snippets of code if you have to start using 
> self.components.data etc.
> 

I have a pythoncard app where I want to know which of a (large)
number of checkboxes gets clicked. I do something like:

    def on_mouseClick(self, event):
        name = event.target.name
        if name in self.availability.times:
            button = getattr(self.components, name)
            avail = self.availability.avail[name]
            #print dir(button)
            if button.checked:
                if button.backgroundColor == AVAIL:
                    self.availability.avail[name] = 1
                else:
                    self.availability.avail[name] = 0
                button.backgroundColor = (255, 255, 255)
            else:
                if self.availability.avail[name]:
                    button.backgroundColor = AVAIL
                else:
                    button.backgroundColor = UNAVAIL


Notice my comment  #print dir(button)  I use those quite often
when doing pythoncard just to see what it is that I have a
handle on, and what I can do with it.




> A second question occurres: Is it possible to create a component at
> run time? If so how would you start.
> Thanks 
> 

I am pretty sure that the pythoncard resource editor is written in
pythoncard, so I would say "yes" and "read the pythoncard source code".





More information about the Python-list mailing list