Home > Article > Backend Development > How to draw a straight line in python
Tkinter is Python’s standard GUI library. Python uses Tkinter to quickly create GUI applications.
Since Tkinter is built into the python installation package, you can import the Tkinter library after installing Python, and IDLE is also used Written in Tkinter, Tkinter can still handle the simple graphical interface easily. (Recommended learning: Python video tutorial)
Create a canvas for drawing
If we want to draw a picture, we need a different element: a
canvas (canvas)
object, which is the object of the Canvas class (provided by the tkinter module).
When we create a canvas, we pass in the width and height of the canvas (in pixels) to Python. Other aspects are the same as the button code:
>>> from tkinter import* >>> tk = Tk() >>> canvas = Canvas(tk,width=500,height=500) >>> canvas.pack()
Note:
pack function
is used to let In the correct position in the canvas display. If this function is not called, nothing will be displayed normally.
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to draw a straight line in python. For more information, please follow other related articles on the PHP Chinese website!