draw 100 lines randomly 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.

Line-

Syntax-

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

Draw a 100 lines randomly :


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)

#create three lines at different x,y coordinate
for i in range(100):
x1=random.randint(50,350)
y1=random.randint(50,350)
x2=random.randint(50,350)
y2=random.randint(50,350)
canvas.create_line(x1,y1,x2,y2)


#hold the screen
win.mainloop()


output-



-In this program, we import random module by import random
-then using for loop we draw a 100 lines at different coordinates.




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!