drawingfunction.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import math
  2. import tkinter.messagebox
  3. from draftboard import customfunctions
  4. custom_function_index = 18 # 字定义函数的序号
  5. func_dict = {}
  6. custom_func_dict = {}
  7. width = 20
  8. SCREEN = None # 设置屏幕
  9. class Logger:
  10. def __call__(self, *args, **kwargs):
  11. global custom_func_dict, func_dict
  12. for i in custom_func_dict:
  13. func_dict[i] = custom_func_dict[i]()
  14. return func_dict
  15. def linear_func():
  16. global func_dict
  17. if tkinter.messagebox.askokcancel("提示", "是否绘制1次函数(点击取消可撤销未执行的函数)"):
  18. func_dict[1] = lambda x: x
  19. else:
  20. func_dict[1] = None
  21. def quadratic_func():
  22. global func_dict
  23. if tkinter.messagebox.askokcancel("提示", "是否绘制2次函数(点击取消可撤销未执行的函数)"):
  24. func_dict[2] = lambda x: x ** 2
  25. else:
  26. func_dict[2] = None
  27. def cubic_function():
  28. global func_dict
  29. if tkinter.messagebox.askokcancel("提示", "是否绘制3次函数(点击取消可撤销未执行的函数)"):
  30. func_dict[4] = lambda x: x ** 3
  31. else:
  32. func_dict[4] = None
  33. def inverse_func():
  34. global func_dict
  35. if tkinter.messagebox.askokcancel("提示", "是否绘制-1次函数(点击取消可撤销未执行的函数)"):
  36. func_dict[3] = lambda x: 1 / x
  37. else:
  38. func_dict[3] = None
  39. def radical_func():
  40. global func_dict
  41. if tkinter.messagebox.askokcancel("提示", "是否绘制根号函数(点击取消可撤销未执行的函数)"):
  42. func_dict[5] = lambda x: x ** (1 / 2)
  43. else:
  44. func_dict[5] = None
  45. def exp_func():
  46. global func_dict
  47. if tkinter.messagebox.askokcancel("提示", "是否绘制指数函数(点击取消可撤销未执行的函数)"):
  48. func_dict[6] = lambda x: 10 ** x
  49. else:
  50. func_dict[6] = None
  51. def log_func():
  52. global func_dict
  53. if tkinter.messagebox.askokcancel("提示", "是否绘制对数函数(点击取消可撤销未执行的函数)"):
  54. func_dict[7] = lambda x: math.log(x, 2)
  55. else:
  56. func_dict[7] = None
  57. def log2_func():
  58. global func_dict
  59. if tkinter.messagebox.askokcancel("提示", "是否绘制对数函数2(点击取消可撤销未执行的函数)"):
  60. func_dict[8] = lambda x: math.log(2, x)
  61. else:
  62. func_dict[8] = None
  63. def sin_func():
  64. global func_dict
  65. if tkinter.messagebox.askokcancel("提示", "是否绘制正弦函数(点击取消可撤销未执行的函数)"):
  66. func_dict[9] = lambda x: math.sin(x)
  67. else:
  68. func_dict[9] = None
  69. def cos_func():
  70. global func_dict
  71. if tkinter.messagebox.askokcancel("提示", "是否绘制余弦函数(点击取消可撤销未执行的函数)"):
  72. func_dict[10] = lambda x: math.cos(x)
  73. else:
  74. func_dict[10] = None
  75. def tan_func():
  76. global func_dict
  77. if tkinter.messagebox.askokcancel("提示", "是否绘制正切函数(点击取消可撤销未执行的函数)"):
  78. func_dict[11] = lambda x: math.tan(x)
  79. else:
  80. func_dict[11] = None
  81. def cot_func():
  82. global func_dict
  83. if tkinter.messagebox.askokcancel("提示", "是否绘制余切函数(点击取消可撤销未执行的函数)"):
  84. func_dict[12] = lambda x: 1 / math.tan(x)
  85. else:
  86. func_dict[12] = None
  87. def sec_func():
  88. global func_dict
  89. if tkinter.messagebox.askokcancel("提示", "是否绘制正割函数(点击取消可撤销未执行的函数)"):
  90. func_dict[13] = lambda x: 1 / math.cos(x)
  91. else:
  92. func_dict[13] = None
  93. def csc_func():
  94. global func_dict
  95. if tkinter.messagebox.askokcancel("提示", "是否绘制余割函数(点击取消可撤销未执行的函数)"):
  96. func_dict[11] = lambda x: 1 / math.sin(x)
  97. else:
  98. func_dict[11] = None
  99. def arcsin_func():
  100. global func_dict
  101. if tkinter.messagebox.askokcancel("提示", "是否绘制反正弦函数(点击取消可撤销未执行的函数)"):
  102. func_dict[12] = lambda x: math.asin(x)
  103. else:
  104. func_dict[12] = None
  105. def arccos_func():
  106. global func_dict
  107. if tkinter.messagebox.askokcancel("提示", "是否绘制反余弦函数(点击取消可撤销未执行的函数)"):
  108. func_dict[13] = lambda x: math.acos(x)
  109. else:
  110. func_dict[13] = None
  111. def arctan_func():
  112. global func_dict
  113. if tkinter.messagebox.askokcancel("提示", "是否绘制反正切函数(点击取消可撤销未执行的函数)"):
  114. func_dict[14] = lambda x: math.atan(x)
  115. else:
  116. func_dict[14] = None
  117. def arccot_func():
  118. global func_dict
  119. if tkinter.messagebox.askokcancel("提示", "是否绘制反余切函数(点击取消可撤销未执行的函数)"):
  120. func_dict[15] = lambda x: 1 / math.atan(x)
  121. else:
  122. func_dict[15] = None
  123. def arcsec_func():
  124. global func_dict
  125. if tkinter.messagebox.askokcancel("提示", "是否绘制反正割函数(点击取消可撤销未执行的函数)"):
  126. func_dict[16] = lambda x: 1 / math.acos(x)
  127. else:
  128. func_dict[16] = None
  129. def arccsc_func():
  130. global func_dict
  131. if tkinter.messagebox.askokcancel("提示", "是否绘制反余割函数(点击取消可撤销未执行的函数)"):
  132. func_dict[17] = lambda x: 1 / math.asin(x)
  133. else:
  134. func_dict[17] = None
  135. def custom_func():
  136. global func_dict, custom_function_index, custom_func_dict
  137. custom_func_dict[custom_function_index] = customfunctions.make_func()
  138. def func_box():
  139. global SCREEN
  140. loger = Logger()
  141. SCREEN = tkinter.Toplevel() # 设置屏幕
  142. SCREEN.title("")
  143. SCREEN.resizable(width=False, height=False)
  144. SCREEN.geometry(f"+180+10")
  145. tkinter.Button(SCREEN, text="1次函数", command=linear_func, width=width, height=1).pack()
  146. tkinter.Button(SCREEN, text="2次函数", command=quadratic_func, width=width, height=1).pack()
  147. tkinter.Button(SCREEN, text="-1次函数", command=inverse_func, width=width, height=1).pack()
  148. tkinter.Button(SCREEN, text="3次函数", command=cubic_function, width=width, height=1).pack()
  149. tkinter.Button(SCREEN, text="根号函数", command=radical_func, width=width, height=1).pack()
  150. tkinter.Button(SCREEN, text="对数函数", command=log_func, width=width, height=1).pack()
  151. tkinter.Button(SCREEN, text="指数函数", command=exp_func, width=width, height=1).pack()
  152. tkinter.Button(SCREEN, text="对数底函数", command=log2_func, width=width, height=1).pack()
  153. tkinter.Button(SCREEN, text="sin函数", command=sin_func, width=width, height=1).pack()
  154. tkinter.Button(SCREEN, text="cos函数", command=cos_func, width=width, height=1).pack()
  155. tkinter.Button(SCREEN, text="tan函数", command=tan_func, width=width, height=1).pack()
  156. tkinter.Button(SCREEN, text="cot函数", command=tan_func, width=width, height=1).pack()
  157. tkinter.Button(SCREEN, text="csc函数", command=csc_func, width=width, height=1).pack()
  158. tkinter.Button(SCREEN, text="sec函数", command=sec_func, width=width, height=1).pack()
  159. tkinter.Button(SCREEN, text="arcsin函数", command=arcsin_func, width=width, height=1).pack()
  160. tkinter.Button(SCREEN, text="arccos函数", command=arccos_func, width=width, height=1).pack()
  161. tkinter.Button(SCREEN, text="arctan函数", command=arctan_func, width=width, height=1).pack()
  162. tkinter.Button(SCREEN, text="arccot函数", command=arccot_func, width=width, height=1).pack()
  163. tkinter.Button(SCREEN, text="arccsc函数", command=arccsc_func, width=width, height=1).pack()
  164. tkinter.Button(SCREEN, text="arcsec函数", command=arcsec_func, width=width, height=1).pack()
  165. tkinter.Button(SCREEN, text="自定义函数", command=custom_func, width=width, height=3).pack()
  166. return loger