加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.py 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
Lingjie Fan 提交于 2023-09-07 23:25 . an example
import tkinter
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
window = tkinter.Tk()
window.title("复旦2023光学荣誉课示例")
f = Figure(figsize=(5,4), dpi=100)
a = f.add_subplot(111)
x = np.arange(0,3,0.01)
y = np.sin(1*2*np.pi*x)+np.sin(1*2*np.pi*x)
a.plot(x,y)
canvas = FigureCanvasTkAgg(f, master=window)
canvas.draw()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=tkinter.YES)
omega1_value = 1*2*np.pi
omgea2_value = 1*2*np.pi
def wave_show(value):
y = np.sin(float(omega1.get())*x)+np.sin(float(omega2.get())*x)
a.clear()
a.plot(x,y)
canvas.draw()
omega1 = tkinter.Scale(window, from_=1*2*np.pi, to = 10*2*np.pi, resolution=0.5*np.pi, length=200, sliderlength=20, label="omega1", orient=tkinter.HORIZONTAL, command=wave_show)
omega2 = tkinter.Scale(window, from_=1*2*np.pi, to = 10*2*np.pi, resolution=0.5*np.pi, length=200, sliderlength=20, label="omega2", orient=tkinter.HORIZONTAL, command=wave_show)
omega1.pack()
omega2.pack()
omega1.set(value=1)
omega2.set(value=1)
window.mainloop()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化