使用 Tkinter Python 繪製圓形
Tkinter 畫布通常用於建立諸如圓弧、矩形、三角形、自由形狀等形狀。所有這些形狀都可以使用 tkinter 庫中的內建函式繪製。
示例
在此示例中,我們將使用create_oval(x0,y0,x1,y1)方法建立圓形,方法是傳遞以下座標值 (x0,y0, x1, y1)
#Import the library from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the geometry of window win.geometry("600x400") #Create a canvas object c= Canvas(win,width=400, height=400) c.pack() #Draw an Oval in the canvas c.create_oval(60,60,210,210) win.mainloop()
輸出
執行以上程式碼將在畫布中繪製一個圓形。在此示例中,我們已將 (x0, y0, x1, y1) 的座標定義為 (60,60,210,210)。因此,它將在視窗中繪製並顯示一個圓形。
廣告