Draw a Graph using canvas Tkinter Python by R4R Team


program-

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

canvas=Canvas(win,bg="white",height=400,width=500)
canvas.place(x=0,y=0)
l=canvas.create_line(100,90,100,325)
l=canvas.create_line(100,150,370,325)
l=canvas.create_line(100,325,390,325)

v=0
for i in range(10):
canvas.create_line(95,100+25*i,105,100+25*i)
v=v+1
t=str(v)
t=t[0:3]
canvas.create_text(85,95+25*i,text=t)

v=-20
for i in range(10):
canvas.create_line(100+30*i,320,100+30*i,330)
v=v+20
canvas.create_text(100+30*i,340,text=v)

for i in range(9):
canvas.create_text(105+30*i,145+20*i,text=".",font=('',20,'bold'))

canvas.update()
#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 x and y axis then draw a line in x,y coordinate and mark some points to better representation of the Map and graphs.
-In this way, by arranginf line we can draw any types of graphs and maps.




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!