如何在 tkinter 畫布上繪製弧形?
畫布是一個矩形區域,用於繪製圖片或其他複雜佈局。你可以在畫布上放置圖形、文字、小部件或框架。
要繪製出一個 tkinter 畫布弧形,我們將會使用畫布的 create_arc() 方法,併為其提供一組座標來繪製弧形。我們可以使用 create_arc() 來建立一個弧形專案,它可以是一個弦、一個扇形或一個簡單的弧形。
步驟 −
匯入所需的庫,並建立一個 tkinter 框架例項。
使用 root.geometry 方法設定框架大小。
建立一個畫布小部件並設定其高度和寬度。此外,用 bg="blue" 設定其背景顏色。
接下來,使用 create_arc 方法繪製弧形。提供弧形的座標,並定義 extent。此處,我們設定 extent=150。
最後,執行應用程式視窗的 mainloop。
示例
# Import the required libraries
from tkinter import *
# Create an instance of Tkinter Frame
root = Tk()
# Set the geometry
root.geometry("700x350")
# Create a Canvas with a background color
C = Canvas(root, bg="blue", height=250, width=600)
# Coordinates for the arc
coord = 100, 50, 500, 300
# Create the arc with extent=150
arc = C.create_arc(coord, start=0, extent=150, fill="red")
C.pack(side=TOP, padx=50, pady=50)
root.mainloop()輸出
在執行中,它將產生以下輸出 −
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP