Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON programming please! Please help with this ex. Write a GUI application Rec

ID: 3773889 • Letter: P

Question

PYTHON programming please!

Please help with this ex.

Write a GUI application Rectangle.py to get rectangle information, calculate area and draw the rectangle. Use entry fields for users to enter the width and height of the rectangle as shown. When user click on Calculate button, calculate and display the result in the Perimeter and Area fields. When user click on Draw button, draw the rectangle with the right width and height in the center of the canvas. When user click on Clear button, clear the drawing and entered fields.

Explanation / Answer

from Tkinter import Tk, Canvas, Frame, BOTH class Example(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.initUI() def initUI(self): self.parent.title("Colours") self.pack(fill=BOTH, expand=1) canvas = Canvas(self) canvas.create_rectangle(30, 10, 120, 80, outline="#fb0", fill="#fb0") canvas.create_rectangle(150, 10, 240, 80, outline="#f50", fill="#f50") canvas.create_rectangle(270, 10, 370, 80, outline="#05f", fill="#05f") canvas.pack(fill=BOTH, expand=1) def main(): root = Tk() ex = Example(root) root.geometry("400x100+300+300") root.mainloop() if __name__ == '__main__': main()