Tkinter, a lot of buttons, make prog shorter?

7stud bbxx789_05ss at yahoo.com
Sun Apr 6 18:21:51 EDT 2008


On Apr 6, 4:12 pm, 7stud <bbxx789_0... at yahoo.com> wrote:
> You said you were an experienced programmer, but you keep posting code
> with the same mistakes over and over again.  Why are you attaching the
> buttons to self?

Remember this:

> Another thing you should be aware of: self is like a class wide
> bulletin board. If you are writing code inside a class method, and
> there is data that you want code inside another class method to be
> able to see, then post the data on the class wide bulletin board, i.e.
> attach it to self.  But in your code, you are doing this:
>
> self.btnDisplay = Button(self, text="7", default=ACTIVE)
> self.btnDisplay.grid(row=5, column=0, padx=5, pady=5)
>
> self.btnDisplay = Button(self, text="8", default=ACTIVE)
> self.btnDisplay.grid(row=5, column=1, padx=5, pady=5)
>
> As a result, your code continually overwrites self.btnDisplay.  That
> means you aren't preserving the data assigned to self.btnDisplay.
> Therefore, the data does not need to be posted on the class wide
> bulletin board for other class methods to see.  So just write:
>
> btnDisplay = Button(self, text="7", default=ACTIVE)
> btnDisplay.grid(row=5, column=0, padx=5, pady=5)
>
> btnDisplay = Button(self, text="8", default=ACTIVE)
> btnDisplay.grid(row=5, column=1, padx=5, pady=5)



More information about the Python-list mailing list