Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Vẽ đường line trên Canvas Tkinter

Canvas Tkinter vẽ hình, graphics. Vẽ line: create_line(x,y,x1,y1, **options). Hai loại: đơn (solid) và nét đứt (dash).

Ví dụ

from tkinter import *

win = Tk()
win.geometry("700x350")

canvas = Canvas(win, width=500, height=300)
canvas.pack()
canvas.create_line(100, 200, 200, 35, fill="green", width=5)
win.mainloop()

Kết quả

Canvas 500x300 với đường line xanh từ (100,200) đến (200,35), độ dày 5px.

Vẽ đường line trên Canvas Tkinter

Tham số create_line: fill (màu), width (độ dày), dash=(on, off) (nét đứt), arrow (mũi tên), capstyle, joinstyle, smooth (cong).