1
0

drawingfunction.py 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. import math
  2. import tkinter.messagebox
  3. from draftboard import customfunctions
  4. width = 20
  5. SCREEN = None # 设置屏幕
  6. bg_color = "#FFFAFA" # 主颜色
  7. botton_color = "#FFFAFA" # 按钮颜色
  8. word_color = "#000000" # 文字颜色
  9. class Logger:
  10. def __init__(self):
  11. self.func_dict = {}
  12. self.custom_loger = {}
  13. self.custom_function_index = 18
  14. def __call__(self, *args, **kwargs):
  15. for i in self.custom_loger:
  16. self.func_dict[i] = self.custom_loger[i]()
  17. return self.func_dict
  18. loger = Logger()
  19. class UIAPI:
  20. @staticmethod
  21. def askok_gui(message):
  22. return tkinter.messagebox.askokcancel('提示', message)
  23. class API:
  24. @staticmethod
  25. def linear_func():
  26. if UIAPI.askok_gui("是否绘制1次函数(点击取消可撤销未执行的函数)"):
  27. loger.func_dict[1] = lambda x: x
  28. else:
  29. loger.func_dict[1] = None
  30. @staticmethod
  31. def quadratic_func():
  32. if UIAPI.askok_gui("是否绘制2次函数(点击取消可撤销未执行的函数)"):
  33. loger.func_dict[2] = lambda x: x ** 2
  34. else:
  35. loger.func_dict[2] = None
  36. @staticmethod
  37. def cubic_function():
  38. if UIAPI.askok_gui("是否绘制3次函数(点击取消可撤销未执行的函数)"):
  39. loger.func_dict[4] = lambda x: x ** 3
  40. else:
  41. loger.func_dict[4] = None
  42. @staticmethod
  43. def inverse_func():
  44. if UIAPI.askok_gui("是否绘制-1次函数(点击取消可撤销未执行的函数)"):
  45. loger.func_dict[3] = lambda x: 1 / x
  46. else:
  47. loger.func_dict[3] = None
  48. @staticmethod
  49. def radical_func():
  50. if UIAPI.askok_gui("是否绘制根号函数(点击取消可撤销未执行的函数)"):
  51. loger.func_dict[5] = lambda x: x ** (1 / 2)
  52. else:
  53. loger.func_dict[5] = None
  54. @staticmethod
  55. def exp_func():
  56. if UIAPI.askok_gui("是否绘制指数函数(点击取消可撤销未执行的函数)"):
  57. loger.func_dict[6] = lambda x: 10 ** x
  58. else:
  59. loger.func_dict[6] = None
  60. @staticmethod
  61. def log_func():
  62. if UIAPI.askok_gui("是否绘制对数函数(点击取消可撤销未执行的函数)"):
  63. loger.func_dict[7] = lambda x: math.log(x, 2)
  64. else:
  65. loger.func_dict[7] = None
  66. @staticmethod
  67. def log2_func():
  68. if UIAPI.askok_gui("是否绘制对数函数2(点击取消可撤销未执行的函数)"):
  69. loger.func_dict[8] = lambda x: math.log(2, x)
  70. else:
  71. loger.func_dict[8] = None
  72. @staticmethod
  73. def sin_func():
  74. if UIAPI.askok_gui("是否绘制正弦函数(点击取消可撤销未执行的函数)"):
  75. loger.func_dict[9] = lambda x: math.sin(x)
  76. else:
  77. loger.func_dict[9] = None
  78. @staticmethod
  79. def cos_func():
  80. if UIAPI.askok_gui("是否绘制余弦函数(点击取消可撤销未执行的函数)"):
  81. loger.func_dict[10] = lambda x: math.cos(x)
  82. else:
  83. loger.func_dict[10] = None
  84. @staticmethod
  85. def tan_func():
  86. if UIAPI.askok_gui("是否绘制正切函数(点击取消可撤销未执行的函数)"):
  87. loger.func_dict[11] = lambda x: math.tan(x)
  88. else:
  89. loger.func_dict[11] = None
  90. @staticmethod
  91. def cot_func():
  92. if UIAPI.askok_gui("是否绘制余切函数(点击取消可撤销未执行的函数)"):
  93. loger.func_dict[12] = lambda x: 1 / math.tan(x)
  94. else:
  95. loger.func_dict[12] = None
  96. @staticmethod
  97. def sec_func():
  98. if UIAPI.askok_gui("是否绘制正割函数(点击取消可撤销未执行的函数)"):
  99. loger.func_dict[13] = lambda x: 1 / math.cos(x)
  100. else:
  101. loger.func_dict[13] = None
  102. @staticmethod
  103. def csc_func():
  104. if UIAPI.askok_gui("是否绘制余割函数(点击取消可撤销未执行的函数)"):
  105. loger.func_dict[11] = lambda x: 1 / math.sin(x)
  106. else:
  107. loger.func_dict[11] = None
  108. @staticmethod
  109. def arcsin_func():
  110. if UIAPI.askok_gui("是否绘制反正弦函数(点击取消可撤销未执行的函数)"):
  111. loger.func_dict[12] = lambda x: math.asin(x)
  112. else:
  113. loger.func_dict[12] = None
  114. @staticmethod
  115. def arccos_func():
  116. if UIAPI.askok_gui("是否绘制反余弦函数(点击取消可撤销未执行的函数)"):
  117. loger.func_dict[13] = lambda x: math.acos(x)
  118. else:
  119. loger.func_dict[13] = None
  120. @staticmethod
  121. def arctan_func():
  122. if UIAPI.askok_gui("是否绘制反正切函数(点击取消可撤销未执行的函数)"):
  123. loger.func_dict[14] = lambda x: math.atan(x)
  124. else:
  125. loger.func_dict[14] = None
  126. @staticmethod
  127. def arccot_func():
  128. if UIAPI.askok_gui("是否绘制反余切函数(点击取消可撤销未执行的函数)"):
  129. loger.func_dict[15] = lambda x: 1 / math.atan(x)
  130. else:
  131. loger.func_dict[15] = None
  132. @staticmethod
  133. def arcsec_func():
  134. if UIAPI.askok_gui("是否绘制反正割函数(点击取消可撤销未执行的函数)"):
  135. loger.func_dict[16] = lambda x: 1 / math.acos(x)
  136. else:
  137. loger.func_dict[16] = None
  138. @staticmethod
  139. def arccsc_func():
  140. if UIAPI.askok_gui("是否绘制反余割函数(点击取消可撤销未执行的函数)"):
  141. loger.func_dict[17] = lambda x: 1 / math.asin(x)
  142. else:
  143. loger.func_dict[17] = None
  144. @staticmethod
  145. def custom_func():
  146. loger.custom_loger[loger.custom_function_index] = customfunctions.make_func()
  147. def func_box():
  148. global SCREEN, loger
  149. loger = Logger()
  150. SCREEN = tkinter.Toplevel(bg=bg_color) # 设置屏幕
  151. SCREEN.title("")
  152. SCREEN.resizable(width=False, height=False)
  153. SCREEN.geometry(f"+180+10")
  154. tkinter.Button(
  155. SCREEN,
  156. text="1次函数",
  157. bg=bg_color,
  158. fg=word_color,
  159. command=API.linear_func,
  160. width=width,
  161. height=1,
  162. ).pack()
  163. tkinter.Button(
  164. SCREEN,
  165. text="2次函数",
  166. bg=bg_color,
  167. fg=word_color,
  168. command=API.quadratic_func,
  169. width=width,
  170. height=1,
  171. ).pack()
  172. tkinter.Button(
  173. SCREEN,
  174. text="-1次函数",
  175. bg=bg_color,
  176. fg=word_color,
  177. command=API.inverse_func,
  178. width=width,
  179. height=1,
  180. ).pack()
  181. tkinter.Button(
  182. SCREEN,
  183. text="3次函数",
  184. bg=bg_color,
  185. fg=word_color,
  186. command=API.cubic_function,
  187. width=width,
  188. height=1,
  189. ).pack()
  190. tkinter.Button(
  191. SCREEN,
  192. text="根号函数",
  193. bg=bg_color,
  194. fg=word_color,
  195. command=API.radical_func,
  196. width=width,
  197. height=1,
  198. ).pack()
  199. tkinter.Button(
  200. SCREEN,
  201. text="对数函数",
  202. bg=bg_color,
  203. fg=word_color,
  204. command=API.log_func,
  205. width=width,
  206. height=1,
  207. ).pack()
  208. tkinter.Button(
  209. SCREEN,
  210. text="指数函数",
  211. bg=bg_color,
  212. fg=word_color,
  213. command=API.exp_func,
  214. width=width,
  215. height=1,
  216. ).pack()
  217. tkinter.Button(
  218. SCREEN,
  219. text="对数底函数",
  220. bg=bg_color,
  221. fg=word_color,
  222. command=API.log2_func,
  223. width=width,
  224. height=1,
  225. ).pack()
  226. tkinter.Button(
  227. SCREEN,
  228. text="sin函数",
  229. bg=bg_color,
  230. fg=word_color,
  231. command=API.sin_func,
  232. width=width,
  233. height=1,
  234. ).pack()
  235. tkinter.Button(
  236. SCREEN,
  237. text="cos函数",
  238. bg=bg_color,
  239. fg=word_color,
  240. command=API.cos_func,
  241. width=width,
  242. height=1,
  243. ).pack()
  244. tkinter.Button(
  245. SCREEN,
  246. text="tan函数",
  247. bg=bg_color,
  248. fg=word_color,
  249. command=API.tan_func,
  250. width=width,
  251. height=1,
  252. ).pack()
  253. tkinter.Button(
  254. SCREEN,
  255. text="cot函数",
  256. bg=bg_color,
  257. fg=word_color,
  258. command=API.tan_func,
  259. width=width,
  260. height=1,
  261. ).pack()
  262. tkinter.Button(
  263. SCREEN,
  264. text="csc函数",
  265. bg=bg_color,
  266. fg=word_color,
  267. command=API.csc_func,
  268. width=width,
  269. height=1,
  270. ).pack()
  271. tkinter.Button(
  272. SCREEN,
  273. text="sec函数",
  274. bg=bg_color,
  275. fg=word_color,
  276. command=API.sec_func,
  277. width=width,
  278. height=1,
  279. ).pack()
  280. tkinter.Button(
  281. SCREEN,
  282. text="arcsin函数",
  283. bg=bg_color,
  284. fg=word_color,
  285. command=API.arcsin_func,
  286. width=width,
  287. height=1,
  288. ).pack()
  289. tkinter.Button(
  290. SCREEN,
  291. text="arccos函数",
  292. bg=bg_color,
  293. fg=word_color,
  294. command=API.arccos_func,
  295. width=width,
  296. height=1,
  297. ).pack()
  298. tkinter.Button(
  299. SCREEN,
  300. text="arctan函数",
  301. bg=bg_color,
  302. fg=word_color,
  303. command=API.arctan_func,
  304. width=width,
  305. height=1,
  306. ).pack()
  307. tkinter.Button(
  308. SCREEN,
  309. text="arccot函数",
  310. bg=bg_color,
  311. fg=word_color,
  312. command=API.arccot_func,
  313. width=width,
  314. height=1,
  315. ).pack()
  316. tkinter.Button(
  317. SCREEN,
  318. text="arccsc函数",
  319. bg=bg_color,
  320. fg=word_color,
  321. command=API.arccsc_func,
  322. width=width,
  323. height=1,
  324. ).pack()
  325. tkinter.Button(
  326. SCREEN,
  327. text="arcsec函数",
  328. bg=bg_color,
  329. fg=word_color,
  330. command=API.arcsec_func,
  331. width=width,
  332. height=1,
  333. ).pack()
  334. tkinter.Button(
  335. SCREEN,
  336. text="自定义函数",
  337. bg=bg_color,
  338. fg=word_color,
  339. command=API.custom_func,
  340. width=width,
  341. height=3,
  342. ).pack()
  343. return loger