adding score when clicking inside rectangle
<p>I have the following exercise to do for school:</p>

<p>Create a textfield which shows a score as follows "Score: " (You can use the text(StringValue, IntegerXposition, IntegerYposition) for the drawing of text), starting at zero.
Make it so that when the user clicks the left mouseButton a score of 10 is added to the result.</p>

<p>Create a rectangle on screen and make it so that when the user clicks inside the rectangle, a score of 20 is added to the score value.</p>

<p>I have done the first part but don't know how to add a score of 20 when clicking inside the rectangle. This is the code i have so far.</p>

<pre><code>def setup():
    global Score, xPos, yPos
    size(800,800)
    textSize(30)
    Score= 0
    xPos= 200
    yPos= 200

def draw():
    global Score, xPos, yPos
    background(51)
    rect(xPos,yPos,100,100)
    text("Score: ", 50, 50)
    text(Score, 150, 50)    


def mousePressed():
    global Score, xPos, yPos
    if (mouseButton == LEFT):
        Score= Score + 10
</code></pre>

<p>I'm not quiet sure if this is possible with just <code>Python/Python 3.5.1</code> alone. I think <code>tkinter</code> is more suitable with making shapes with Python (And I'm not quiet sure because, I never used it before). I would suggest you use a <code>class</code> initialization for this. Here is what I got:</p>

<pre><code>class shapesYo:
    def __init__(self, xPos, yPos):
        self.xPos = xPos
        self.yPos = yPos
        self.size = (800, 800)
    def displayPos(self):
        print("The x Position is {0} and the y Position is {1}.".format(self.xPos, self.yPos))
    def displayScore(self):
        self.Score = 0
        print("Score: {0}".format(self.Score))

rect = shapesYo(100, 100)
text = shapesYo(50, 50)
rect.displayPos()
text.displayPos()
text.displayScore()
</code></pre>

<p>This may not help out with the actual events happening (or that you want to happen) in the code but, it is a better was (in my opinion) to setup a set of code like this.</p>

python python-3.x