Draw A Basic Line In Python GUI Application

In this blog, I am going to drawing a basic line in Python GUI application

Intro

In this blog, I am going to show how to draw a line in 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

  1. #Drawing basic line on the canvas  
  2. from tkinter import *  
  3. from tkinter import ttk  
  4. app=Tk()  
  5. #App Title  
  6. app.title("Python GUI Application ")  
  7. #Lable  
  8. name=ttk.Label(app, text="Draw basic line")  
  9. name.pack()  
  10. #Canvas  
  11. canvas=Canvas(app)  
  12. canvas.pack()  
  13. canvas.config(width=480,height=360)  
  14. #Canvas values  
  15. line=canvas.create_line(60,160,280,90,fill='blue',width=5)  
  16. #Calling Main()  
  17. app.mainloop()  

About the code

First, I am importing the tkinter modules.

Next, I assign a class and give 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