Canvas 위젯은 Tkinter 애플리케이션에서 그래픽 표현을 위해 가장 널리 사용되는 위젯 중 하나입니다. Canvas 위젯에 라인을 표시하기 위해 내장 라이브러리 메소드 create_line(x1,y1,x2,y2, **options)을 사용할 수 있습니다. .
대시를 사용하여 선 유형을 지정할 수도 있습니다. 특성. 선 유형을 실선에서 대시로 변경하려면 동적으로 configure()를 사용할 수 있습니다. 방법. 대시에 빈 값 전달 속성에서 선을 실선으로 변경할 수 있습니다. 대시 .
예
작동 방식을 보기 위해 예를 들어 보겠습니다.
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the tkinter window
win.geometry("700x350")
def update_line():
canvas.itemconfig(line, dash=())
# Create a canvas widget
canvas=Canvas(win, width=400, height=300)
canvas.pack()
# Create a line
canvas.create_line(300, 30, 300, 150, dash=(4, 2), width=5)
# create a button to change the dash property of the line
ttk.Button(win, text="Change", command=update_line)
win.mainloop() 출력
위의 코드를 실행하면 Canvas 위젯 내부에 점선이 표시됩니다.
