Draw a rectangle by Tkinter Python by R4R Team

What is canvas ?
- Canvas is a geometry material thing like line, circle, rectangle etc.
- To draw a canvas like structure, many programming language like c, c++, python, java etc supports this.

rectangle-
Syntax-

canvas.create_rectangle(x1,y1,x2,y2,option,...)

-Here (x1,y1) and (x2,y2) are different ends of the rectangle.


program-

from tkinter import *
import random
#create a window screen
win=Tk()
win.geometry("500x400")

canvas=Canvas(win,bg="white",height=400,width=500)
canvas.place(x=0,y=0)

canvas.create_rectangle(30,30,150,150,fill="green")
canvas.create_rectangle(200,150,300,200,fill="blue")
canvas.create_rectangle(250,250,450,350)


#hold the screen
win.mainloop()


output-



-In this program, we firslty create a canvas window inside the window screen by using canvas=Canvas(win).
-Then we create a three rectangles with differnt orientation with different colours and 'fill' are used to fill the colour inside the rectangle.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!