Форум сайта python.su
Добрый день!
Задача этой части проги: открывается окно -> выбираем dif -> отображается окно для дифференцирования -> нажимаем на “Choose function” и выбираем функцию галочкой ->нажимаем “Chose function” и у нас должна отобразиться выбранная функция и условия к ней (если есть)-> повторяем те же действия и для подфункции
Проблема: когда функцию def dif() прописываем как отдельную программу - всё работает без ошибок (см. фото1). Когда же мы прописываем как функцию def dif() - идёт отображение интерфейса, есть возможность выбора функции в “choose function”, но после нажатия “chose function” ничего не происходит
Буду благодарен за помощь в решении данного вопроса.
from Tkinter import * from math import* def dif(): zadanie1 = Tk() framea= Frame (zadanie1) framea.grid(row=0, column=0) frameb=Frame (zadanie1, width=400, height=450) frameb.grid(row=0, column=1) frame1=Frame (framea, width=0, height=10) frame1.grid(row=0, column=0) frame2=Frame (zadanie1, width=10, height=10) frame2.grid(row=3, column=0) frame3=Frame (framea, width=10, height=10) frame3.grid(row=6, column=1) frame4=Frame (framea, width=10, height=10) frame4.grid(row=11, column=1) frame5=Frame (framea, width=10, height=10) frame5.grid(row=6, column=4) frame6=Frame (framea, width=10, height=10) frame6.grid(row=11, column=4) #Начало выбора функции F_label = Label(framea, text="Function").grid(row=3, column=0,pady=5) f_label = Label(framea, text="") f_label.grid(row=3, column=1,pady=5) G_label = Label(framea, text="Deritative").grid(row=4, column=0,pady=5) g_label = Label(framea, text="") g_label.grid(row=4, column=1,pady=5) U_label = Label(framea, text="Additional condition \n for function ").grid(row=5, column=0,pady=5) u_label = Label(framea, text="") u_label.grid(row=5, column=1,pady=5) enter_label = Label(framea, text="Enter: ").grid(row=6, column=0,pady=5) p_label = Label(frame3, text="") p_label.grid(row=0, column=0,pady=5) entry=Entry(frame3, width=0) entry.grid(row=0, column=1,pady=5) var=IntVar() W=Menubutton(framea,text="Choose function",relief=RAISED) W.menu=Menu(W,tearoff=1) W['menu']=W.menu W.menu.add_radiobutton(label = "t**n", variable = var,value=1) W.menu.add_radiobutton(label = "a**t", variable = var,value=2) W.menu.add_radiobutton(label = "log(b)t", variable = var,value=3) W.menu.add_radiobutton(label = "exp(t)", variable = var,value=4) W.menu.add_radiobutton(label = "ln(t)", variable = var,value=5) W.menu.add_radiobutton(label = "sin(t)", variable = var,value=6) W.menu.add_radiobutton(label = "cos(t)", variable = var,value=7) W.menu.add_radiobutton(label = "sqrt(t)", variable = var,value=8) W.menu.add_radiobutton(label = "C", variable = var,value=9) W.menu.add_radiobutton(label = "tg(t)", variable = var,value=10) W.menu.add_radiobutton(label = "ctg(t)", variable = var,value=11) W.menu.add_radiobutton(label = "arcsin(t)", variable = var,value=12) W.menu.add_radiobutton(label = "arccos(t)", variable = var,value=13) W.menu.add_radiobutton(label = "arctg(t)", variable = var,value=14) W.menu.add_radiobutton(label = "arcctg(t)", variable = var,value=15) W.menu.add_radiobutton(label = "sinh(t) ", variable = var,value=16) W.menu.add_radiobutton(label = "cosh(t)", variable = var,value=17) W.menu.add_radiobutton(label = "tgh(t)", variable = var,value=18) W.menu.add_radiobutton(label = "ctgh(t)", variable = var,value=19) W.grid(row=2, column=0) #Окончание выбора функции #Начало выбора подфункции F_label2 = Label(framea, text="Function").grid(row=8, column=0,pady=5) f_label2 = Label(framea, text="") f_label2.grid(row=8, column=1,pady=5) G_label2 = Label(framea, text="Deritative").grid(row=9, column=0,pady=5) g_label2 = Label(framea, text="") g_label2.grid(row=9, column=1,pady=5) U_label2 = Label(framea, text="Additional condition\n for subfunction").grid(row=10, column=0,pady=5) u_label2 = Label(framea, text="") u_label2.grid(row=10, column=1,pady=5) enter_label2= Label(framea, text="Enter: ").grid(row=11, column=0,pady=5) p_label2 = Label(frame4, text="") p_label2.grid(row=0, column=0,pady=5) entry2=Entry(frame4, width=0) entry2.grid(row=0, column=1,pady=5) var2=IntVar() w=Menubutton(framea,text="Choose subfunction",relief=RAISED) w.menu=Menu(w,tearoff=1) w['menu']=w.menu w.menu.add_radiobutton(label = "x**n", variable = var2,value=1) w.menu.add_radiobutton(label = "a**x", variable = var2,value=2) w.menu.add_radiobutton(label = "log(b)x", variable = var2,value=3) w.menu.add_radiobutton(label = "exp(x)", variable = var2,value=4) w.menu.add_radiobutton(label = "ln(x)", variable = var2,value=5) w.menu.add_radiobutton(label = "sin(x)", variable = var2,value=6) w.menu.add_radiobutton(label = "cos(x)", variable = var2,value=7) w.menu.add_radiobutton(label = "sqrt(x)", variable = var2,value=8) w.menu.add_radiobutton(label = "C", variable = var2,value=9) w.menu.add_radiobutton(label = "tg(x)", variable = var2,value=10) w.menu.add_radiobutton(label = "ctg(x)", variable = var2,value=11) w.menu.add_radiobutton(label = "arcsin(x)", variable = var2,value=12) w.menu.add_radiobutton(label = "arccos(x)", variable = var2,value=13) w.menu.add_radiobutton(label = "arctg(x)", variable = var2,value=14) w.menu.add_radiobutton(label = "arcctg(x)", variable = var2,value=15) w.menu.add_radiobutton(label = "sinh(x) ", variable = var2,value=16) w.menu.add_radiobutton(label = "cosh(x)", variable = var2,value=17) w.menu.add_radiobutton(label = "tgh(x)", variable = var2,value=18) w.menu.add_radiobutton(label = "ctgh(x)", variable = var2,value=19) w.grid(row=7, column=0) def chose(): if var.get()==1: f_label.config(text="t**n") g_label.config(text="n*((t)**(n-1))") u_label.config(text="n \n n!=0 \n -n in N, x!=0 \n n !in Z, x>0") entry.config(width=0) entry.config(width=5) p_label.config(text='n') if var.get()==2: f_label.config(text="a**t") g_label.config(text="(a**t)*log(a)") u_label.config(text=" a \n a>0 \n a!=1") entry.config(width=0) entry.config(width=5) p_label.config(text='a') if var.get()==3: f_label.config(text="log(b)t") g_label.config(text="1/(t*log(b))") u_label.config(text="b \n b>0 \n b!=1") entry.config(width=0) entry.config(width=5) p_label.config(text='b') if var.get()==4: f_label.config(text="exp(t)") g_label.config(text="exp(t)") u_label.config(text="") entry.config(width=0) p_label.config(text='Nothing') if var.get()==5: f_label.config(text="ln(t)") g_label.config(text="1/t") u_label.config(text="t>0") entry.config(width=0) p_label.config(text='Nothing') if var.get()==6: f_label.config(text="sin(t)") g_label.config(text="cos(t)") u_label.config(text="") entry.config(width=0) p_label.config(text='Nothing') if var.get()==7: f_label.config(text="cos(t)") g_label.config(text="-sin(t)") u_label.config(text="") entry.config(width=0) p_label.config(text='Nothing') if var.get()==8: f_label.config(text="sqrt(t)") g_label.config(text="1/(2*sqrt(t)))") u_label.config(text="t>0") entry.config(width=0) p_label.config(text='Nothing') if var.get()==9: f_label.config(text="C") g_label.config(text="0") u_label.config(text="") entry.config(width=0) p_label.config(text='Nothing') if var.get()==10: f_label.config(text="tg(t)") g_label.config(text="1/(cos(t)**2)") u_label.config(text="t!=n*(pi/2)") entry.config(width=0) p_label.config(text='Nothing') if var.get()==11: f_label.config(text="ctg(x)") g_label.config(text=" -1/(sin(t)**2)") u_label.config(text="x!=n*pi") entry.config(width=0) p_label.config(text='Nothing') if var.get()==12: f_label.config(text="arcsin(x)") g_label.config(text="1/(sqrt(1-(t**2)))") u_label.config(text="-1<t<1") entry.config(width=0) p_label.config(text='Nothing') if var.get()==13: f_label.config(text="arccos(x)") g_label.config(text="-1/(sqrt(1-(x**2)))") u_label.config(text="-1<t<1") entry.config(width=0) p_label.config(text='Nothing') if var.get()==14: f_label.config(text="arctg(x)") g_label.config(text="1/(1+t**2)") u_label.config(text="") entry.config(width=0) p_label.config(text='Nothing') if var.get()==15: f_label.config(text="arcctg(t)") g_label.config(text="-1/(1+t**2)") u_label.config(text="") entry.config(width=0) p_label.config(text='Nothing') if var.get()==16: f_label.config(text="sinh(t) ") g_label.config(text="cosh(t)") u_label.config(text="") entry.config(width=0) p_label.config(text='Nothing') if var.get()==17: f_label.config(text="cosh(t) ") g_label.config(text="sinh(t)") u_label.config(text="") entry.config(width=0) p_label.config(text='Nothing') if var.get()==18: f_label.config(text="tgh(t) ") g_label.config(text="1/(cosh(t)**2)") u_label.config(text="") entry.config(width=0) p_label.config(text='Nothing') if var.get()==19: f_label.config(text="ctgh(t) ") g_label.config(text="-1/(sinh(t)**2)") u_label.config(text="") entry.config(width=0) p_label.config(text='Nothing') def chose2(): if var2.get()==1: f_label2.config(text="x**n") g_label2.config(text="n*((x)**(n-1))") u_label2.config(text="n \n n!=0 \n -n in N, x!=0 \n n !in Z, x>0") entry2.config(width=0) entry2.config(width=5) p_label2.config(text='n') if var2.get()==2: f_label2.config(text="a**x") g_label2.config(text="(a**x)*log(a)") u_label2.config(text=" a \n a>0 \n a!=1") entry2.config(width=0) entry2.config(width=5) p_label2.config(text='a') if var2.get()==3: f_label2.config(text="log(b)x") g_label2.config(text="1/(x*log(b))") u_label2.config(text="b \n b>0 \n b!=1") entry2.config(width=0) entry2.config(width=5) p_label2.config(text='b') if var2.get()==4: f_label2.config(text="exp(x)") g_label2.config(text="exp(x)") u_label2.config(text="") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==5: f_label2.config(text="ln(x)") g_label2.config(text="1/x") u_label2.config(text="x>0") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==6: f_label2.config(text="sin(x)") g_label2.config(text="cos(x)") u_label2.config(text="") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==7: f_label2.config(text="cos(x)") g_label2.config(text="-sin(x)") u_label2.config(text="") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==8: f_label2.config(text="sqrt(x)") g_label2.config(text="1/(2*sqrt(x)))") u_label2.config(text="x>0") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==9: f_label2.config(text="C") g_label2.config(text="0") u_label2.config(text="") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==10: f_label2.config(text="tg(x)") g_label2.config(text="1/(cos(x)**2)") u_label2.config(text="x!=n*(pi/2)") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==11: f_label2.config(text="ctg(x)") g_label2.config(text=" -1/(sin(x)**2)") u_label2.config(text="x!=n*pi") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==12: f_label2.config(text="arcsin(x)") g_label2.config(text="1/(sqrt(1-(x**2)))") u_label2.config(text="-1<x<1") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==13: f_label2.config(text="arccos(x)") g_label2.config(text="-1/(sqrt(1-(x**2)))") u_label2.config(text="-1<x<1") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==14: f_label2.config(text="arctg(x)") g_label2.config(text="1/(1+x**2)") u_label2.config(text="") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==15: f_label2.config(text="arcctg(x)") g_label2.config(text="-1/(1+x**2)") u_label2.config(text="") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==16: f_label2.config(text="sinh(x) ") g_label2.config(text="cosh(x)") u_label2.config(text="x in radians") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==17: f_label2.config(text="cosh(x)") g_label2.config(text="sinh(x)") u_label2.config(text="x in radians") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==18: f_label2.config(text="tgh(x) ") g_label2.config(text="1/(cosh(x)**2)") u_label2.config(text="x in radians") entry2.config(width=0) p_label2.config(text='Nothing') if var2.get()==19: f_label2.config(text="ctgh(x) ") g_label2.config(text="-1/(sinh(x)**2)") u_label2.config(text="x in radians") entry2.config(width=0) p_label2.config(text='Nothing') Button1 = Button(frame2, text="Chose function", width=15, command=chose).grid(row=0, column=0, padx=5) Button2 = Button(frame2, text="Chose subfunction", width=15, command=chose2).grid(row=0, column=1, padx=5) zadanie1.mainloop() viborf=Tk() viborftext= Label(viborf, text='Chose task') viborftext.grid (row=1, column=2) viborfbutton1= Button (viborf, text='Diff',command=dif) viborfbutton1.grid(row=2, column= 2, padx=5, pady=5) viborf.mainloop()
Прикреплённый файлы:
фото1.png (88,4 KБ)
Офлайн