Home  >  Article  >  Backend Development  >  How to draw a straight line in python

How to draw a straight line in python

(*-*)浩
(*-*)浩Original
2019-07-02 14:52:5410671browse

Tkinter is Python’s standard GUI library. Python uses Tkinter to quickly create GUI applications.

How to draw a straight line in python

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()

How to draw a straight line in python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn