<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Python Inheritence Help' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Python Inheritence Help' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Wed, 23 May 2012 23:42:43 -0700</pubDate>
    <lastBuildDate>Wed, 23 May 2012 23:42:43 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Python Inheritence Help</title>
      <link>http://www.programmersheaven.com/mb/python/410142/410142/python-inheritence-help/</link>
      <description>I have a simple button class to make buttons&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
from graphics import *

class Button:

    """A button is a labeled rectangle in a window.
    It is activated or deactivated with the activate()
    and deactivate() methods. The clicked(p) method
    returns true if the button is active and p is inside it."""

    def __init__(self, win, center, width, height, label):
        """ Creates a rectangular button, eg:
        qb = Button(myWin, Point(30,25), 20, 10, 'Quit') """ 

        w,h = width/2.0, height/2.0
        x,y = center.getX(), center.getY()
        self.xmax, self.xmin = x+w, x-w
        self.ymax, self.ymin = y+h, y-h
        p1 = Point(self.xmin, self.ymin)
        p2 = Point(self.xmax, self.ymax)
        self.rect = Rectangle(p1,p2)
        self.rect.setFill('lightgray')
        self.rect.draw(win)
        self.label = Text(center, label)
        self.label.draw(win)
        self.deactivate()

    def clicked(self, p):
        "Returns true if button active and p is inside"
        return self.active and \
               self.xmin &amp;lt;= p.getX() &amp;lt;= self.xmax and \
               self.ymin &amp;lt;= p.getY() &amp;lt;= self.ymax

    def getLabel(self):
        "Returns the label string of this button."
        return self.label.getText()

    def activate(self):
        "Sets this button to 'active'."
        self.label.setFill('black')
        self.rect.setWidth(2)
        self.active = True

    def deactivate(self):
        "Sets this button to 'inactive'."
        self.label.setFill('darkgrey')
        self.rect.setWidth(1)
        self.active = False
&lt;/pre&gt;&lt;br /&gt;
and I wanted to make a CustomButton class which inherited Button, except with a black button and green text, I tried this&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
class CustomButton(Button):
	def __init__(self, win, center, width, height, label):
		        self.rect.setFill('black')
			self.label.setFill('green')
&lt;/pre&gt;&lt;br /&gt;
But I get this error:&lt;br /&gt;
&lt;br /&gt;
Traceback (most recent call last):&lt;br /&gt;
  File "calc.pyw", line 104, in &amp;lt;module&amp;gt;&lt;br /&gt;
    theCalc = Calculator()&lt;br /&gt;
  File "calc.pyw", line 21, in __init__&lt;br /&gt;
    self.__createButtons()&lt;br /&gt;
  File "calc.pyw", line 37, in __createButtons&lt;br /&gt;
    self.buttons.append(CustomButton(self.win,Point(cx
,cy),.75,.75,label))&lt;br /&gt;
  File "calc.pyw", line 11, in __init__&lt;br /&gt;
    self.rect.setFill('black')&lt;br /&gt;
AttributeError: CustomButton instance has no attribute 'rect'&lt;br /&gt;
&lt;br /&gt;
Do I need to rewrite the entire __init__ to change this?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/410142/410142/python-inheritence-help/</guid>
      <pubDate>Tue, 01 Dec 2009 13:13:10 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Python Inheritence Help</title>
      <link>http://www.programmersheaven.com/mb/python/410142/410143/re-python-inheritence-help/#410143</link>
      <description>actually came up with this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;class CustomButton(Button):
	def changeColors(self,label,bg,outline):
		self.label.setFill(label)
		self.rect.setFill(bg)
		self.rect.setOutline(outline)&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
and then just change it after making the button objects&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/410142/410143/re-python-inheritence-help/#410143</guid>
      <pubDate>Tue, 01 Dec 2009 18:17:28 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>
