如何在tkinter上制作圆形画布?

时间:2017-08-28 21:38:42

标签: python canvas tkinter

我一直在尝试编写一个能够绘制圆形图形的函数。我尝试使用距离公式来计算我的观点:

@Override
public void GETCoins() {
    String url = "https://www.cryptocompare.com/api/data/coinlist/";
    Log.d("Debug ", "URL:  " + url);

    //Run async task to pull weather data. weatherTask.get... forces main thread to wait for this to finish
    HTTPAsyncTask coinTask = new HTTPAsyncTask(this);
    coinTask.execute(url, "GET");
    try {
        JSONObject jsonObject = new JSONObject(coinTask.get());

        JSONObject obj = new JSONObject(jsonObject.getString("Data"));

        Iterator<?> keys = obj.keys();
        int i = 0;
        while(keys.hasNext() ) {

            String key = (String) keys.next();

            if(obj.get(key) instanceof JSONObject) {
                JSONObject val = new JSONObject(obj.get(key).toString());

                String imageUrl = baseImageUrl + val.getString("ImageUrl");
                String name = val.getString("Name");
                String currency = val.getString("CoinName");

                CryptoData data = new CryptoData(i, currency, 0,0, imageUrl, name);

                allCurrencyList.add(data);
                i++;
            }
        }

        //updateData(jsonObject);

    } catch (InterruptedException | JSONException | ExecutionException e) {
        e.printStackTrace();
    } finally {
        Log.d("Debug ", "Coin API is null");
    }
}

那不起作用,所以我看了别人的代码圈。这就是:

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

我在数学上很不错,但我不确定这意味着什么。

1 个答案:

答案 0 :(得分:1)

我认为这样做的标准方法是使用create_oval。

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

create_oval Documentation

希望它有所帮助。干杯!