Hello guys, I really need help with this one. Can you please help me create a program in Python that displays information about a rectangle of any size.
Input: two mouse clicks for the opposite corners of a rectangle
Output: Draw the rectangle. Print the perimeter and area of the rectangle
Formulas: Area = (length)(width)
We can help you if you make a start on the code to show your commited to your project :)
I would recommend that you look into using a program called PyGame. Start of making some basic programs such as how to open a window with PyGame and then how to draw a rectangle. Then you can use PyGame to detect the mouse position and pass it to the functions. PyGame has some excellent documentation pages: http://pygame.org/docs/
I have this but I dont know how to code it so that it works with only two clicks, 4 works but not 2.
There is a line missing somewhere, such as
win = GraphWin("My Rectangle", 300, 300)
Apart from that, this is good python code
You can do it with 2 clicks if you realize that 2 points give you 2 values for x and 2 values for y. With these values, you can build 4 different points and draw the rectangle.
As this thread is 3 years old and Fo.katia is probably not waiting for an answer, you could write the complete running solution with 2 clicks in a code snippet. (select the type Code Snippet after you click Start a new discussion).
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...