Introduction
In this blog, I am going to show how to draw a line in the Python GUI application. It will display a basic line on the application screen.
Software requirement
Python 3.5 and IDLE (Python 3.5)
Programming code
-
- from tkinter import *
- from tkinter import ttk
- app=Tk()
-
- app.title("Python GUI Application ")
-
- name=ttk.Label(app, text="Draw basic line")
- name.pack()
-
- canvas=Canvas(app)
- canvas.pack()
- canvas.config(width=480,height=360)
-
- line=canvas.create_line(60,160,280,90,fill='blue',width=5)
-
- app.mainloop()
About the code
First, I am importing the tkinter modules.
Next, I assign a class and give the application title.
Next, I use canvas class and assign the line values and line color in the code.
Finally, I have started the Windows event loop by calling the mainloop method.
Then, let’s execute the code.
Output