tkinter如化画正弦波
时间: 2023-12-28 17:25:26 浏览: 48
Painter绘制正弦图
以下是使用tkinter绘制正弦波的示例代码:
```python
import tkinter as tk
import math
# 创建画布
root = tk.Tk()
canvas = tk.Canvas(root, width=800, height=400)
canvas.pack()
# 绘制坐标轴
canvas.create_line(50, 200, 750, 200, width=2) # x轴
canvas.create_line(50, 50, 50, 350, width=2) # y轴
# 绘制正弦波
x_start = 50
y_start = 200
scale = 50 # 控制波形的振幅
for x in range(0, 800):
y = y_start - math.sin((x - x_start) / scale) * scale
canvas.create_line(x, y, x + 1, y + 1, fill='red')
# 运行窗口
root.mainloop()
```
阅读全文