2017-08-28 39 views
-2

我一直想寫將繪製一個circle.I使用距離公式以計算我的觀點試過功能:如何在tkinter的畫布上做圓圈?

def distance_form(x1, y1, x2, y2): 
    d = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) 
    return d 

這並沒有工作,所以我看了看某人其他人的代碼爲圓。這裏是:

def circle(page, radius, g, h): 
    for x in range(g, g + radius): 
     y = h + (math.sqrt(radius ** 2 - ((x - g) ** 2))) 
     plot(page, x, y) 
     plot(page, x, 2 * h - y) 
     plot(page, 2 * g - x, y) 
     plot(page, 2 * g - x, 2 * h - y) 

我在數學方面很體面,但我不確定這是什麼意思。

+0

Google [tkinter canvas create circle](https://www.google.com/search?newwindow=1&biw=1280&bih=945&q=tkinter+canvas+create+circle&oq=tkinter+canvas+create+circle&gs_l=psy-ab) .3 ... 2139.2891.0.3017.8.6.0.0.0.0.0.0..0.0 .... 0 ... 1.1.64.psy-ab..8.0.0.Okm7VcQmnc0)[第一個結果](https: (看起來很有前途)(http://zetcode.com/gui/tkinter/drawing/)...嘗試谷歌搜索在提出一個容易找到文檔的問題之前,問一下問題可能會阻止你在將來提出問題。 –

+0

tkinter沒有一個叫做'plot'的方法。你在使用其他庫,比如matplotlib嗎? –

+0

@Brian Oakley哦,我已經定義了陰謀已經創建一條線 – Fibo36

回答

1

我認爲這樣做的標準方法是使用create_oval。

oval = canvas.create_oval(x0, y0, x1, y1, options) 

create_oval Documentation

希望它幫助。乾杯!