Computer Science, asked by roysahisht, 8 months ago

Hello...I have a question about my python homework:
Write a menu driven program to draw shapes:
It can be:
1.Square
2.Rectangle
3.Triangle
Define functions to draw the shapes and call them in main program
The user should enter the choice of which shape to draw and depending on choice corresponding functions should be called.​

Answers

Answered by kirtipadhi06
1

Answer:

from tkinter import *

def square():

Canvas.create_square(x1, y1, x2, y2)

#here x1 , x2, y1, y2 are the coordinates of the corner points.

def rectangle():

Canvas.create_rectangle(x1,y1,x2,y2)

def triangle():

Canvas.create_triangle(x1,y1,x2,y2)

print("What would you like to create?")

print("press 1 for square")

print("press 2 for rectangle")

print(*press 3 for triangle")

shape=int(input("Enter your choice:")

if shape==1:

square()

elif shape==2:

rectangle()

elif shape==3:

triangle()

else:

print("please enter a valid choice")

You can use Canvas widget to create any shape and this can be imported using Tkinter GUI.

Tkinter is not available in Python IDLE. It would be better if you use Spyder of pycharm to do codings.

Above code is simple one. If you want to know about making buttons and labels or widget like animated app, then feel free to ask me.

Hope this helps you!

Similar questions