TK_DoneHS.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import tkinter
  2. import tkinter.messagebox
  3. import math
  4. help_Wo = '''
  5. 请在第一个输入框输入你的函数方程,不需要输入f(x)=和y=,唯一变量是x(x为自变量)
  6. 圆周率-Pi,自然无理数-e
  7. 指数的表示符号:**,比如x**2表示x的二次方
  8. 对数的表示符号:log(a,b),其中a是真书,b是底数(没有lg和ln)
  9. 三角函数sin(),cos(),tan(),cot(),csc(),sec()
  10. 反三角函数arcsin(),arccos(),arctan()
  11. 双曲函数:sinh(),cosh(),tanh()
  12. 注意:三角函数必须带括号使用
  13. 不支持定义域选择,不支持分段函数
  14. '''
  15. class HS_lambda:
  16. def __init__(self,HS):
  17. self.HS = HS
  18. self.Name = {'x':0,'Pi':math.pi,'e':math.e,'log':math.log,
  19. 'sin':math.sin,'cos':math.cos,'tan':math.tan,
  20. 'cot':lambda x:1/math.tan(x),'csc':lambda x:1/math.sin(x),
  21. 'sec':lambda x:1/math.cos(x),'sinh':math.sinh,'cosh':math.cosh,
  22. 'tanh':math.tanh,'asin':math.asin,'acos':math.acos,
  23. 'atan':math.atan}
  24. def __call__(self,x):
  25. self.Name['x'] = x
  26. return eval(self.HS,self.Name)
  27. def Sure():
  28. global HS_Input,HS,help_Wo
  29. Input = HS_Input.get().replace(' ', '')
  30. if Input:
  31. if tkinter.messagebox.askokcancel('提示', f'是否确认生成自定义函数:\n{HS_Input.get()}\n(点击取消可撤销未执行的制造函数)'):
  32. HS = HS_lambda(HS_Input.get())
  33. else:HS = None
  34. else:
  35. if tkinter.messagebox.askokcancel('提示', f'点击确定撤销为执行的制造函数'):
  36. HS = None
  37. def Help():
  38. tkinter.messagebox.showinfo(title='帮助', message=help_Wo)
  39. def Done_HS():
  40. global HS_Input,HS,top
  41. HS = None
  42. top = tkinter.Tk() # 设置屏幕
  43. top.title('')
  44. top.resizable(width=False, height=False)
  45. top.geometry(f'+350+10')
  46. button = tkinter.Button(top, text="制造函数", command=Sure,width=28,height=1) # 收到消息执行这个函数
  47. help = tkinter.Button(top, text="帮助", command=Help, width=28, height=1) # 帮助菜单
  48. HS_Input = tkinter.Entry(top)
  49. HS_Input.pack(fill=tkinter.BOTH)
  50. button.pack()
  51. help.pack()
  52. top.mainloop()
  53. return HS