Ok i am having a little trouble trying to figure out how to pull the x-cordinate from p1 and p2 so that i can use it later in the code to build a door.

# This is a program to build a house in five clicks

from graphics import *

def main():

win = GraphWin("house.py", 400, 300)
win.setCoords(0,0, 4,3)

p1 = win.getMouse()
p2 = win.getMouse()

house = Rectangle(p1, p2)
house.setFill("red")
house.draw(win)

win.getMouse()
win.close()

main()

There is no module called graphics in normal Python distribution! Without this custom module will be hard to help!

I suggest you print p1 and see what it looks like!
If it is tuple like (30, 45), then most likely p1x = p1[0].

There is no module called graphics in normal Python distribution! Without this custom module will be hard to help!

I suggest you print p1 and see what it looks like!
If it is tuple like (30, 45), then most likely p1x = p1[0].

Ok there is no such thing as a "graphics" module in python true, but all the "graphics" module is Tkinter with a wrapper around it. So if you know of away to address the problem in Tkinter thats great.

Thanks for the help.

Alright, you're off to a pretty good start with the five click house program. I'm assuming you have the graphics.py file in your python directory from what you've written so far. You were right that you want to create a rectangle with p1 as the bottom left corner and p2 as the top right corner. However, you need to get the x and y values of your mouse clicks to make those mouse clicks into a "point." To do this, you want to use p1.getX() and p1.getY(). After doing that, your code should look something like this:

house = Rectangle(Point(p1.getX(), p1.getY()), Point(p2.getX(), p2.getY()))

You will want to use this same method for the rest of the house and make sure that you do the math right so the house has the correct proportions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.