๐Ÿ
B.TECH I YEAR โ€ข II SEMESTER โ€ข R25

Python Programming - Lab Manual

Python Programming Laboratory โ€ข Program Solution

๐Ÿ“˜ R25 Regulation ๐ŸŽ“ I Year ๐Ÿ“š II Semester ๐Ÿ Python Programming ๐Ÿงช Lab Program
Selected Program

draw_rectangle

โ† All Python Programs

Aim:

☛   Add an attribute named color to your Rectangle objects and modify draw_rectangle so that it uses the color attribute as the fill color.

Solution :


PROGRAM: (fill_rectangle.py)

 
from tkinter import *
# Create an instance of tkinter frame
root = Tk ()
# Create Title
root.title(" Rectangle ")
# create canvas object
widget = Canvas(root, width = 700 , height = 400 , bg = "grey")
#function
def draw_rectangle(windget,rect):
	print(rect)
# Read Co-ordinates
x1 = int(input(" Enter x1 value = " ))
y1 = int(input(" Enter y1 value = " ))
x2 = int(input(" Enter x2 value = " ))
y2 = int(input(" Enter y2 value = " ))
# create object for rectangle
rect = widget.create_rectangle(x1,y1,x2,y2,fill="red")
# call function by passing canvas & rectangle objects as argument
draw_rectangle(widget,rect)
widget.pack()
root.mainloop()

OUTPUT:

 
 Enter x1 value = 100
 Enter y1 value = 30
 Enter x2 value = 250
 Enter y2 value = 100

image

๐Ÿ’ป Run This Python Program

draw_rectangle
The selected Python program is loaded automatically into the editor. Edit the program, provide input if required and click Run.

The compiler is embedded using OneCompiler. Your Python program runs inside the embedded Python environment; Study Glance does not execute Python code directly on your web server.
โ† Back to Python Lab Programs ๐Ÿ“š All Lab Manuals