python3.7.3 tkinter canvas画圆角矩形形成代码
时间: 2023-08-03 21:39:45 浏览: 235
以下是画圆角矩形的 Python 3.7.3 tkinter canvas 代码:
```python
from tkinter import *
# 创建画布
root = Tk()
canvas = Canvas(root, width=400, height=400)
canvas.pack()
# 画圆角矩形
x1, y1, x2, y2 = 100, 100, 300, 300
r = 50
canvas.create_arc(x1, y1, x1+r, y1+r, start=90, extent=90, style="arc")
canvas.create_arc(x2-r, y1, x2, y1+r, start=0, extent=90, style="arc")
canvas.create_arc(x2-r, y2-r, x2, y2, start=270, extent=90, style="arc")
canvas.create_arc(x1, y2-r, x1+r, y2, start=180, extent=90, style="arc")
canvas.create_line(x1+r/2, y1, x2-r/2, y1)
canvas.create_line(x2, y1+r/2, x2, y2-r/2)
canvas.create_line(x2-r/2, y2, x1+r/2, y2)
canvas.create_line(x1, y2-r/2, x1, y1+r/2)
canvas.create_rectangle(x1+r/2, y1, x2-r/2, y2, fill="blue")
# 进入消息循环
root.mainloop()
```
在这个代码段中,我们使用 `create_arc` 方法来绘制四个圆弧,用 `create_line` 方法来绘制矩形的四条边,最后用 `create_rectangle` 方法来填充矩形内部的颜色。你可以根据需要调整参数来改变圆角矩形的大小和颜色。
阅读全文