用python 的tkinter画三个圆,填充颜色分别为浅灰,灰和深灰色
时间: 2024-02-11 12:05:55 浏览: 77
下面是一个用 Python 的 tkinter 库画三个圆,填充颜色分别为浅灰,灰和深灰色的示例代码:
```python
import tkinter as tk
# 创建一个窗口
root = tk.Tk()
# 创建一个画布
canvas = tk.Canvas(root, width=300, height=300)
canvas.pack()
# 画一个浅灰色圆
x0, y0, x1, y1 = 50, 50, 100, 100
canvas.create_oval(x0, y0, x1, y1, fill='#D3D3D3', outline='')
# 画一个灰色圆
x0, y0, x1, y1 = 100, 100, 150, 150
canvas.create_oval(x0, y0, x1, y1, fill='#808080', outline='')
# 画一个深灰色圆
x0, y0, x1, y1 = 150, 150, 200, 200
canvas.create_oval(x0, y0, x1, y1, fill='#696969', outline='')
# 运行窗口
root.mainloop()
```
在上面的代码中,我们首先创建了一个窗口和一个画布。然后我们分别画了三个圆,填充颜色分别为浅灰,灰和深灰色。我们使用 `create_oval` 方法画圆,传入圆的左上角和右下角坐标以及填充颜色和边框颜色。最后,我们使用 `mainloop` 方法运行窗口。
运行上面的代码,你应该可以看到三个填充颜色不同的圆。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)