from tkinter import * import math root = Tk() root.title('Побудова графіка функції y=sin(x)') root.geometry('1320x640') canvas = Canvas(root, width=1040, height=640, bg='#002') canvas.pack(side='right') for y in range(21): k=50*y canvas.create_line(20+k,620,20+k,20,width=1,fill='#191938') for x in range(13): k=50*x canvas.create_line(20,20+k,1020,20+k,width=1,fill='#191938') canvas.create_line(20,20,20,620,width=1,arrow=FIRST, fill='white') canvas.create_line(10,320,1020,320,width=1,arrow=LAST, fill='white') canvas.create_text(20,10,text='300',fill='white') canvas.create_text(20,630,text='-300',fill='white') canvas.create_text(10,310,text='0',fill='white') canvas.create_text(1030,310,text='1000',fill='white') label_w=Label(root,text='Частота:') label_w.place(x=0,y=10) label_phi=Label(root,text='Зміщення по X:') label_phi.place(x=0,y=30) label_A=Label(root,text='Амплітуда:') label_A.place(x=0,y=50) label_dy=Label(root,text='Зміщення по Y:') label_dy.place(x=0,y=70) entry_w=Entry(root,width=10); entry_w.place(x=150,y=10); entry_w.insert(0,'0.209') entry_phi=Entry(root,width=10); entry_phi.place(x=150,y=30); entry_phi.insert(0,'10') entry_A=Entry(root,width=10); entry_A.place(x=150,y=50); entry_A.insert(0,'200') entry_dy=Entry(root,width=10); entry_dy.place(x=150,y=70); entry_dy.insert(0,'310') def sinus(w,phi,A,dy): global sin sin=0 xy=[] for x in range(1000): y=math.sin(x*w) xy.append(x+phi) xy.append(y*A+dy) sin=canvas.create_line(xy,fill='blue') def clean(): canvas.delete(sin) btn_calc=Button(root,text='Побудувати') btn_calc.bind('',lambda event:sinus(float(entry_w.get()), float(entry_phi.get()), float(entry_A.get()), float(entry_dy.get() ))) btn_calc.place(x=10,y=100) btn_clean=Button(root,text='Очистити') btn_clean.bind('',lambda event:clean()) btn_clean.place(x=120,y=100) root.mainloop()