Func_advanced.py 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  1. from __future__ import division # 让/恢复为除法
  2. import sympy
  3. from matplotlib import pyplot as plt
  4. from matplotlib import rcParams
  5. import tkinter
  6. import tkinter.messagebox
  7. import random
  8. from New_TK import DragWindow
  9. from matplotlib.animation import FuncAnimation
  10. from HSCH.HS import HS_lambda as HS_L
  11. import numpy as np
  12. def type_selection(IN, si=float, n=True): # Float筛选系统
  13. x = []
  14. for i in IN:
  15. try:
  16. if si(i) == si(0) and n:
  17. continue
  18. x.append(si(i))
  19. except ValueError:
  20. pass
  21. return x
  22. def save_to_csv(): # 导出CSV
  23. try:
  24. succ = HS.Out() # 是否成功
  25. if not succ:
  26. raise Exception
  27. output_prompt('CSV导出成功')
  28. except BaseException:
  29. output_prompt('CSV导出失败')
  30. def to_sheet(): # 生成表格
  31. global HS, Pr_BOX
  32. try:
  33. Pr_BOX.delete(0, tkinter.END)
  34. Pr_BOX.insert(tkinter.END, *HS.returnList())
  35. output_prompt('表格创建成功')
  36. except BaseException:
  37. output_prompt('无法创建表格')
  38. def sympy_computing(c) -> tuple:
  39. try:
  40. Name = {
  41. 'Pi': sympy.pi,
  42. 'e': sympy.E,
  43. 'log': sympy.log,
  44. 'sin': sympy.sin,
  45. 'cos': sympy.cos,
  46. 'tan': sympy.tan,
  47. 'cot': lambda x: 1 / sympy.tan(x),
  48. 'csc': lambda x: 1 / sympy.sin(x),
  49. 'sec': lambda x: 1 / sympy.cos(x),
  50. 'sinh': sympy.sinh,
  51. 'cosh': sympy.cosh,
  52. 'tanh': sympy.tanh,
  53. 'asin': sympy.asin,
  54. 'acos': sympy.acos,
  55. 'atan': sympy.atan}
  56. ans = eval(c, Name)
  57. return ans, True
  58. except BaseException:
  59. return None, False
  60. # 确认表达式被正确计算
  61. def confirmation_expression(c):
  62. get = sympy_computing(c)
  63. if not get[1]:
  64. return c
  65. return get[0]
  66. def check_center_of_symmetry():
  67. global HS, YC_Input, YC_BOX, XZ_JD
  68. a, must = sympy_computing(XZ_JD.get())
  69. try:
  70. G = HS.Check_Center_of_symmetry(confirmation_expression(YC_Input.get()), output_prompt, a)
  71. if G[1]:
  72. YC_BOX.insert(tkinter.END, G[1])
  73. output_prompt('预测完成')
  74. else:
  75. raise Exception
  76. except BaseException:
  77. output_prompt('预测失败')
  78. def check_symmetry_axis():
  79. global HS, YC_Input, YC_BOX, XZ_JD
  80. a, must = sympy_computing(XZ_JD.get())
  81. try:
  82. G = HS.Check_Symmetry_axis(confirmation_expression(YC_Input.get()), output_prompt, a)
  83. if G[1]:
  84. YC_BOX.insert(tkinter.END, G[1])
  85. output_prompt('预测完成')
  86. else:
  87. raise Exception
  88. except BaseException:
  89. output_prompt('预测失败')
  90. def check_periodic():
  91. global HS, YC_Input, YC_BOX, XZ_JD
  92. a, must = sympy_computing(XZ_JD.get())
  93. try:
  94. G = HS.Check_Periodic(confirmation_expression(YC_Input.get()), output_prompt, a)
  95. if G[1]:
  96. YC_BOX.insert(tkinter.END, G[1])
  97. output_prompt('预测完成')
  98. else:
  99. raise Exception
  100. except BaseException:
  101. output_prompt('预测失败')
  102. def check_monotonic():
  103. global HS, YC_Input, YC_BOX, XZ_JD
  104. a, must = sympy_computing(XZ_JD.get())
  105. try:
  106. G = HS.Check_Monotonic(YC_Input.get(), output_prompt, a)
  107. if G[1]:
  108. YC_BOX.insert(tkinter.END, G[1])
  109. output_prompt('预测完成')
  110. else:
  111. raise Exception
  112. except BaseException:
  113. output_prompt('预测失败')
  114. def clear_memory():
  115. global HS
  116. try:
  117. if tkinter.messagebox.askokcancel('提示', f'确定删除{HS}的记忆吗?'):
  118. R_cul.delete(0, tkinter.END)
  119. HS.Clear_Memory()
  120. output_prompt('删除完毕')
  121. else:
  122. output_prompt('删除取消')
  123. except BaseException:
  124. output_prompt('删除失败')
  125. def show_hidden_memory(): # 显示xy
  126. global HS, R_cul
  127. try:
  128. R_cul.delete(0, tkinter.END)
  129. HS.YC_On_Off()
  130. output_prompt('已清空卡槽')
  131. except BaseException:
  132. output_prompt('隐藏(显示)失败')
  133. def show_memory(): # 显示xy
  134. global HS, R_cul
  135. try:
  136. Fucn = HS[lb.curselection()[0]]
  137. R_cul.delete(0, tkinter.END)
  138. m_x, m_y = Fucn.getMemory()
  139. answer = []
  140. for i in range(len(m_x)):
  141. answer.append(f'x={m_x[i]} -> y={m_y[i]}')
  142. R_cul.insert(tkinter.END, *answer)
  143. output_prompt('输出完成')
  144. except BaseException:
  145. output_prompt('操作失败')
  146. def gradient_method_calculation():
  147. global HS, Xcul_TD_Input, Xcul_TD_CS, R_cul
  148. try:
  149. output_prompt('计算过程程序可能无响应')
  150. R_cul.delete(0, tkinter.END) # 清空
  151. E = []
  152. for i in Xcul_TD_CS:
  153. E.append(i.get())
  154. output_prompt('系统运算中')
  155. answer = HS.Iterative_method_Of_Huan(Xcul_TD_Input.get(), *E)
  156. if answer[1] is not None:
  157. R_cul.insert(tkinter.END, answer[0])
  158. output_prompt('系统运算完成')
  159. else:
  160. output_prompt('系统运算无结果')
  161. except BaseException:
  162. output_prompt('系统运算失败,请注意参数设置')
  163. def calculate():
  164. global Ycul_Input, HS, R_cul
  165. try:
  166. output_prompt('计算过程程序可能无响应')
  167. R_cul.delete(0, tkinter.END)
  168. x = Ycul_Input.get().split(',')
  169. answer = HS.Cul_Y(x)
  170. if answer != []:
  171. R_cul.insert(tkinter.END, *answer)
  172. output_prompt('系统运算完毕')
  173. else:
  174. output_prompt('系统运算无结果')
  175. except BaseException:
  176. output_prompt('计算失败')
  177. def sympy_calculation_x():
  178. global Xcul_DS_Input, HS, R_cul
  179. try:
  180. output_prompt('计算过程程序可能无响应')
  181. R_cul.delete(0, tkinter.END)
  182. x = Xcul_DS_Input.get().split(',')
  183. answer = []
  184. for i in x:
  185. answer += HS.Sympy_Cul(i)[0]
  186. if answer != []:
  187. R_cul.insert(tkinter.END, *answer)
  188. output_prompt('系统运算完毕')
  189. else:
  190. output_prompt('系统运算无结果')
  191. except BaseException:
  192. output_prompt('计算失败')
  193. def function_differentiation():
  194. global DScul_Input, HS, R_cul, DScul_JD_Input
  195. try:
  196. output_prompt('计算过程程序可能无响应')
  197. R_cul.delete(0, tkinter.END)
  198. x = DScul_Input.get().split(',')
  199. JD = DScul_JD_Input.get()
  200. answer = []
  201. for i in x:
  202. get = HS.Sympy_DHS(i, JD)[0]
  203. if get is not None:
  204. answer.append(get)
  205. if answer != []:
  206. R_cul.insert(tkinter.END, *answer)
  207. output_prompt('系统运算完毕')
  208. else:
  209. output_prompt('系统运算无结果')
  210. except IndexError:
  211. output_prompt('计算失败')
  212. def approximation():# 逼近法
  213. global DScul_Input, HS, R_cul, DScul_JD_Input
  214. try:
  215. output_prompt('计算过程程序可能无响应')
  216. R_cul.delete(0, tkinter.END)
  217. x = DScul_Input.get().split(',')
  218. JD = DScul_JD_Input.get()
  219. answer = []
  220. for i in x:
  221. get = HS.Sympy_DHS(i, JD, True)[0]
  222. if get is not None:
  223. answer.append(get)
  224. if answer != []:
  225. R_cul.insert(tkinter.END, *answer)
  226. output_prompt('系统运算完毕')
  227. else:
  228. output_prompt('系统运算无结果')
  229. except IndexError:
  230. output_prompt('计算失败')
  231. def dichotomy():# 二分法
  232. global Xcul_Input, Xcul_CS, HS, R_cul
  233. try:
  234. output_prompt('计算过程程序可能无响应')
  235. R_cul.delete(0, tkinter.END) # 清空
  236. y = Xcul_Input.get().split(',') # 拆解输入
  237. E = [100, 0.0001, 0.1, 0.5, False, True, 1000, 0.1, 0.1, False, None]
  238. for i in range(11):
  239. try:
  240. if i in (4, 5, 9):
  241. a = Xcul_CS[i].get()
  242. else:
  243. a = float(Xcul_CS[i].get())
  244. E[i] = a
  245. except BaseException:
  246. pass
  247. answer = []
  248. output_prompt('系统运算中')
  249. for i in y:
  250. try:
  251. answer += HS.Cul_dichotomy(float(i), *E)[0]
  252. except BaseException:
  253. pass
  254. if answer:
  255. output_prompt('系统运算完成')
  256. R_cul.insert(tkinter.END, *answer)
  257. else:
  258. output_prompt('系统运算无结果')
  259. except BaseException:
  260. output_prompt('系统运算失败')
  261. def property_prediction():
  262. global HS, lb, XZ_BOX, XZ_JD
  263. try:
  264. a, must = sympy_computing(XZ_JD.get())
  265. output_prompt('预测过程程序可能无响应')
  266. XZ_BOX.delete(0, tkinter.END)
  267. answer = HS.Nature(output_prompt, True, a, must)
  268. XZ_BOX.insert(tkinter.END, *answer)
  269. output_prompt('性质预测完成')
  270. except IndexError:
  271. output_prompt('性质预测失败')
  272. def function_drawing():
  273. global XZ_Input, XZstart_Input, XZend_Input, XZkd_Input, YZ_Input, YZstart_Input, YZend_Input, YZkd_Input
  274. global Xlimstart_Input, Xlimend_Input, Ylimstart_Input, Ylimend_Input
  275. global HS, fig, Point_Draw, Best_Draw, Test_Draw, Draw_BOX, ZL_Input
  276. try:
  277. Draw_Type = Draw_BOX.curselection()[0]
  278. except BaseException:
  279. Draw_Type = 0
  280. # 画板创造
  281. output_prompt('生成绘制取...')
  282. fig = plt.figure(num='CoTan函数') # 定义一个图像窗口
  283. if Draw_Type in (0, 1, 2, 3, 8, 9):
  284. plt.grid(True, ls='--') # 显示网格(不能放到后面,因为后面调整成为了笛卡尔坐标系)
  285. ax = plt.gca()
  286. def init():
  287. if Draw_Type in (0, 2, 4, 6, 8):
  288. ax.spines['right'].set_color('none')
  289. ax.spines['top'].set_color('none')
  290. ax.xaxis.set_ticks_position('bottom')
  291. ax.yaxis.set_ticks_position('left')
  292. ax.spines['bottom'].set_position(('data', 0)) # 设置x轴, y轴在(0, 0)的位置
  293. ax.spines['left'].set_position(('data', 0))
  294. # 检测x
  295. try:
  296. if XZ_Input.get()[0] == 'c': # 如果输入函数cx#-10#10#1#1
  297. _HS = [
  298. XZ_Input.get()[
  299. 1:],
  300. XZstart_Input.get(),
  301. XZend_Input.get(),
  302. XZkd_Input.get(),
  303. 2] # 第一部分HS,第二部分S,第三部分E,第四部分KD,第五部分JD
  304. P = ['x', -10, 10, 1, 2] # 保护系统
  305. try:
  306. P[0] = _HS[0]
  307. P[1] = int(_HS[1])
  308. P[2] = int(_HS[2])
  309. P[3] = int(_HS[3])
  310. P[4] = int(_HS[4])
  311. except BaseException: # 迭代匹配直到出现错误
  312. pass
  313. _HS = P
  314. x = type_selection(
  315. HS_L(
  316. _HS[0],
  317. 'x',
  318. '',
  319. _HS[1],
  320. _HS[2],
  321. _HS[3],
  322. _HS[4]).Cul()[1]) # 取y
  323. ax.set_xticks(x)
  324. elif XZ_Input.get()[0] == 'y': # 输入函数y
  325. # 不错要错误捕捉,外围有个大的捕捉
  326. x = abs(int(XZstart_Input.get()))
  327. x_major_locator = plt.MultipleLocator(x)
  328. ax.xaxis.set_major_locator(x_major_locator)
  329. else: # 输入纯数字
  330. x = type_selection(XZ_Input.get().split(','))
  331. ax.set_xticks(x)
  332. except BaseException:
  333. x_major_locator = plt.MultipleLocator(2)
  334. ax.xaxis.set_major_locator(x_major_locator)
  335. # 检测y
  336. try: # 意外捕捉
  337. if YZ_Input.get()[0] == 'c': # 如果输入函数cx#-10#10#1#1
  338. _HS = [
  339. YZ_Input.get()[
  340. 1:],
  341. YZstart_Input.get(),
  342. YZend_Input.get(),
  343. YZkd_Input.get(),
  344. 2] # 第一部分HS,第二部分S,第三部分E,第四部分KD,第五部分JD
  345. P = ['x', -10, 10, 1, 2] # 保护系统
  346. try:
  347. P[0] = _HS[0]
  348. P[1] = int(_HS[1])
  349. P[2] = int(_HS[2])
  350. P[3] = int(_HS[3])
  351. P[4] = int(_HS[4])
  352. except BaseException: # 迭代匹配直到出现错误
  353. pass
  354. _HS = P
  355. y = type_selection(
  356. HS_L(
  357. _HS[0],
  358. 'y',
  359. '',
  360. _HS[1],
  361. _HS[2],
  362. _HS[3],
  363. _HS[4]).Cul()[1]) # 取y
  364. ax.set_yticks(y)
  365. elif YZ_Input.get()[0] == 'y': # 输入函数y
  366. y = abs(int(YZstart_Input.get()))
  367. y_major_locator = plt.MultipleLocator(y)
  368. ax.yaxis.set_major_locator(y_major_locator)
  369. else:
  370. y = type_selection(YZ_Input.get().split(','))
  371. ax.set_yticks(y)
  372. except BaseException:
  373. y_major_locator = plt.MultipleLocator(2)
  374. ax.yaxis.set_major_locator(y_major_locator)
  375. # 极限设计
  376. try:
  377. xlim_IN = type_selection(
  378. [Xlimstart_Input.get(), Xlimend_Input.get()], si=int, n=False)
  379. ylim_IN = type_selection(
  380. [Ylimstart_Input.get(), Ylimend_Input.get()], si=int, n=False)
  381. try:
  382. _xlim = [xlim_IN[0], xlim_IN[1]]
  383. except BaseException:
  384. _xlim = [-10, 10]
  385. try:
  386. _ylim = [ylim_IN[0], ylim_IN[1]]
  387. except BaseException:
  388. _ylim = _xlim
  389. except BaseException:
  390. _xlim = [-10, 10]
  391. _ylim = [-10, 10]
  392. _xlim.sort()
  393. _ylim.sort()
  394. ax.set_xlim(_xlim)
  395. ax.set_ylim(_ylim)
  396. global text_x, text_y
  397. text_x = _xlim[0] + abs(_xlim[0]) * 0.01
  398. text_y = _ylim[1] - abs(_ylim[1]) * 0.01
  399. init()
  400. # 函数绘图系统
  401. output_prompt('图像绘制中...')
  402. if HS is None:
  403. return False
  404. if Draw_Type in (0, 1, 4, 5):
  405. # 绘制曲线
  406. get = HS.Draw_Cul()
  407. fx = get[0]
  408. fy = get[1]
  409. Func_label = get[2]
  410. View = get[3]
  411. First = True
  412. for i in range(len(fx)):
  413. x = fx[i]
  414. y = fy[i]
  415. if First:
  416. plt.plot(x, y, View, label=Func_label) # plot()画出曲线
  417. First = False
  418. else:
  419. plt.plot(x, y, View)
  420. # 绘制记忆点
  421. get = HS.getMemory()
  422. m_x = get[0]
  423. m_y = get[1]
  424. max_x, max_y, min_x, min_y = HS.Best_value()
  425. if Point_Draw.get():
  426. plt.plot(
  427. m_x,
  428. m_y,
  429. View[0] + 'o',
  430. label=f'Point of {Func_label}') # 画出一些点
  431. len_x = sorted(list(set(m_x))) # 去除list重复项目
  432. JZD = max_x + min_x
  433. if Test_Draw.get():
  434. o_x = None
  435. for i in range(len(len_x)):
  436. if i in JZD:
  437. continue # 去除极值点
  438. _x = len_x[i] # x
  439. if o_x is None or abs(_x - o_x) >= 1: # 确保位置
  440. num = m_x.index(_x) # y的座位
  441. _y = m_y[num]
  442. plt.text(
  443. _x, _y, f'({_x},{int(_y)})', fontdict={
  444. 'size': '10', 'color': 'b'}) # 标出坐标
  445. o_x = _x
  446. if Best_Draw.get():
  447. o_x = None
  448. n_max = []
  449. for i in range(len(max_x)): # 画出最大值
  450. _x = max_x[i]
  451. if o_x is None or abs(_x - o_x) >= 1: # 确保位置
  452. if Test_Draw.get():
  453. plt.text(
  454. _x - 1,
  455. max_y,
  456. f'max:({_x},{int(max_y)})',
  457. fontdict={
  458. 'size': '10',
  459. 'color': 'b'}) # 标出坐标
  460. n_max.append(_x)
  461. o_x = _x
  462. o_x = None
  463. n_min = []
  464. for i in range(len(min_x)): # 画出最小值
  465. _x = min_x[i]
  466. if o_x is None or abs(_x - o_x) >= 1:
  467. n_min.append(_x)
  468. if Test_Draw.get():
  469. plt.text(
  470. _x - 1,
  471. min_y,
  472. f'min:({_x},{int(min_y)})',
  473. fontdict={
  474. 'size': '10',
  475. 'color': 'b'}) # 标出坐标
  476. o_x = _x
  477. plt.plot(n_min, [min_y] * len(n_min), View[0] + 'o') # 画出一些点
  478. plt.plot(n_max, [max_y] * len(n_max), View[0] + 'o') # 画出一些点
  479. plt.legend() # 显示图示
  480. elif Draw_Type in (8, 9):
  481. get = HS.Cul()
  482. x = get[0]
  483. y = get[1]
  484. l = len(x)
  485. global xdata, ydata
  486. xdata = []
  487. ydata = []
  488. Func_label = get[2]
  489. View = get[3]
  490. ln = ax.plot([], [], View, label=Func_label, animated=False)[0]
  491. text = plt.text(
  492. text_x, text_y, '', fontdict={
  493. 'size': '10', 'color': 'b'})
  494. def _init():
  495. init()
  496. return ln, text
  497. def update(n):
  498. global xdata, ydata
  499. if n == 0:
  500. xdata = []
  501. ydata = []
  502. xdata.append(x[n])
  503. ydata.append(y[n])
  504. text.set_text(f'x={x[n]},y={y[n]}')
  505. ln.set_data(xdata, ydata)
  506. return ln, text
  507. try: # 自定义帧率
  508. ZL = int(ZL_Input.get())
  509. except BaseException:
  510. ZL = 100
  511. ani = FuncAnimation(
  512. fig,
  513. update,
  514. frames=l,
  515. init_func=_init,
  516. interval=ZL,
  517. blit=False,
  518. repeat_delay=3000) # 动态绘图
  519. elif Draw_Type in (2, 3, 6, 7):
  520. text = plt.text(
  521. text_x, text_y, '', fontdict={
  522. 'size': '10', 'color': 'b'})
  523. HS_List = HS.Return_Son()
  524. pr_List = []
  525. l = len(HS_List)
  526. m = [] # 每个群组中fx分类的个数
  527. for i in HS_List: # 预先生成函数
  528. output_prompt(f'迭代计算中...(共{l}次)')
  529. get = i.Draw_Cul()
  530. m.append(len(get[0]))
  531. pr_List.append(get)
  532. pr_List += pr_List[::-1]
  533. ln_list = [text]
  534. for i in range(max(m)):
  535. ln_list.append(
  536. ax.plot(
  537. [],
  538. [],
  539. pr_List[0][3],
  540. animated=False)[0]) # 创建足够的i
  541. l = len(pr_List)
  542. def _init():
  543. init()
  544. text.set_text('')
  545. return None
  546. def update(n):
  547. get = pr_List[n - 1]
  548. ln_list[0].set_text(get[2])
  549. for i in range(max(m)):
  550. try:
  551. x = get[0][i]
  552. y = get[1][i]
  553. ln_list[i + 1].set_data(x, y)
  554. except BaseException:
  555. ln_list[i + 1].set_data([], [])
  556. return ln_list
  557. try: # 自定义帧率
  558. ZL = int(ZL_Input.get())
  559. except BaseException:
  560. ZL = 100
  561. ani = FuncAnimation(
  562. fig,
  563. update,
  564. frames=l,
  565. init_func=_init,
  566. interval=ZL,
  567. blit=False) # 动态绘图
  568. output_prompt('绘制完毕')
  569. plt.show() # 显示图像
  570. return True
  571. def set_function():
  572. global Func_Input, start_Input, end_Input, kd_Input, JD_Input, FuncName_Input, FuncView_Input, View_C, View_Co, HS, top
  573. global a_MR, a_start, a_end, a_kd
  574. getHS = Func_Input.get().replace(' ', '')
  575. if getHS == '':
  576. output_prompt('应用失败')
  577. return None
  578. X_I = [-10, 10, 0.1, 2, 1, -10, 10, 1]
  579. get = [
  580. start_Input,
  581. end_Input,
  582. kd_Input,
  583. JD_Input,
  584. a_MR,
  585. a_start,
  586. a_end,
  587. a_kd]
  588. # 参数的处理
  589. try:
  590. c = kd_Input.get().replace(' ', '')
  591. if c[0] == 'H':
  592. Name = {
  593. 'Pi': sympy.pi,
  594. 'e': sympy.E,
  595. 'log': sympy.log,
  596. 'sin': sympy.sin,
  597. 'cos': sympy.cos,
  598. 'tan': sympy.tan,
  599. 'cot': lambda x: 1 / sympy.tan(x),
  600. 'csc': lambda x: 1 / sympy.sin(x),
  601. 'sec': lambda x: 1 / sympy.cos(x),
  602. 'sinh': sympy.sinh,
  603. 'cosh': sympy.cosh,
  604. 'tanh': sympy.tanh,
  605. 'asin': sympy.asin,
  606. 'acos': sympy.acos,
  607. 'atan': sympy.atan}
  608. kd = eval(c[1:], Name)
  609. else:
  610. raise Exception
  611. except BaseException:
  612. kd = None
  613. for i in range(8):
  614. try:
  615. a = float(get[i].get())
  616. X_I[i] = a
  617. except BaseException:
  618. pass
  619. if kd is not None:
  620. X_I[2] = kd
  621. # View的处理
  622. view = FuncView_Input.get().split('#')
  623. try:
  624. if view[0] not in View_Co:
  625. view[0] = 'b'
  626. v_2 = View_C.get(view[1], '-')
  627. except BaseException:
  628. view = ['', '']
  629. view[0] = random.choice(View_Co)
  630. v_2 = '-'
  631. V = view[0] + v_2
  632. # Name的处理
  633. name = FuncName_Input.get().replace(' ', '')
  634. if name == '':
  635. name = getHS
  636. try:
  637. HS = HS_L(getHS, name, V, *X_I, c_Son=True)
  638. output_prompt('应用成功')
  639. top.title(f'CoTan函数工厂 {HS}')
  640. except BaseException:
  641. output_prompt('应用失败')
  642. def output_prompt(News):
  643. global News_BOX, T, top
  644. T += 1
  645. News = str(News)
  646. News_BOX.insert(0, News + f'({T})')
  647. top.update()
  648. def function_factory_main(): # H_S-默认函数GF-关闭时询问返回函数
  649. global View_C, View_Co, HS, T, top
  650. HS = None
  651. T = 0
  652. View_C = {'实线': '-',
  653. '短横线': '--',
  654. '点划线': '-,',
  655. '虚线': ':',
  656. '点标记': '.',
  657. '圆标记': 'o',
  658. '倒三角': 'v',
  659. '正三角': '^',
  660. '左三角': '&lt',
  661. '下箭头': '1',
  662. '上箭头': '2',
  663. '左箭头': '3',
  664. '右箭头': '4',
  665. '正方形': 's',
  666. '五边形': 'p',
  667. '星形': '*',
  668. '六边形': 'h',
  669. '六边形2': 'H',
  670. '+号': '+',
  671. 'X标记': 'x', } # 函数样式翻译表
  672. View_Co = ['g', 'r', 'c', 'm', 'y', 'k']
  673. # top = tkinter.Tk() # 设置屏幕
  674. top = DragWindow()
  675. bg = '#FFFAFA' # 主颜色
  676. bbg = '#FFFAFA' # 按钮颜色
  677. fg = '#000000' # 文字颜色
  678. top["bg"] = bg
  679. top.title('CoTan函数工厂')
  680. top.resizable(width=False, height=False)
  681. top.geometry('+10+10')
  682. FONT = (r'Font\ZKST.ttf', 11) # 设置字体
  683. rcParams['font.family'] = 'simhei'
  684. rcParams['axes.unicode_minus'] = False
  685. width_B = 13 # 标准宽度
  686. height_B = 2
  687. a_y = 0
  688. a_x = 1
  689. global Func_Input, start_Input, end_Input, kd_Input, JD_Input, FuncName_Input, FuncView_Input
  690. tkinter.Label(
  691. top,
  692. text='输入解析式:',
  693. bg=bg,
  694. fg=fg,
  695. font=FONT,
  696. width=width_B,
  697. height=height_B).grid(
  698. column=a_x,
  699. row=a_y) # 设置说明
  700. Func_Input = tkinter.Entry(top, width=width_B * 2)
  701. Func_Input.grid(
  702. column=a_x +
  703. 1,
  704. row=a_y,
  705. columnspan=2,
  706. sticky=tkinter.E +
  707. tkinter.W)
  708. a_y += 1
  709. tkinter.Label(
  710. top,
  711. text='定义域前端点:',
  712. bg=bg,
  713. fg=fg,
  714. font=FONT,
  715. width=width_B,
  716. height=height_B).grid(
  717. column=a_x,
  718. row=a_y) # 设置说明
  719. start_Input = tkinter.Entry(top, width=width_B * 2)
  720. start_Input.grid(
  721. column=a_x +
  722. 1,
  723. row=a_y,
  724. columnspan=2,
  725. sticky=tkinter.E +
  726. tkinter.W)
  727. a_y += 1
  728. tkinter.Label(
  729. top,
  730. text='定义域后端点:',
  731. bg=bg,
  732. fg=fg,
  733. font=FONT,
  734. width=width_B,
  735. height=height_B).grid(
  736. column=a_x,
  737. row=a_y) # 设置说明
  738. end_Input = tkinter.Entry(top, width=width_B * 2)
  739. end_Input.grid(
  740. column=a_x +
  741. 1,
  742. row=a_y,
  743. columnspan=2,
  744. sticky=tkinter.E +
  745. tkinter.W)
  746. a_y += 1
  747. tkinter.Label(
  748. top,
  749. text='函数绘制跨度:',
  750. bg=bg,
  751. fg=fg,
  752. font=FONT,
  753. width=width_B,
  754. height=height_B).grid(
  755. column=a_x,
  756. row=a_y) # 设置说明
  757. kd_Input = tkinter.Entry(top, width=width_B * 2)
  758. kd_Input.grid(
  759. column=a_x +
  760. 1,
  761. row=a_y,
  762. columnspan=2,
  763. sticky=tkinter.E +
  764. tkinter.W)
  765. a_y += 1
  766. tkinter.Label(
  767. top,
  768. text='函数计算精度:',
  769. bg=bg,
  770. fg=fg,
  771. font=FONT,
  772. width=width_B,
  773. height=height_B).grid(
  774. column=a_x,
  775. row=a_y) # 设置说明
  776. JD_Input = tkinter.Entry(top, width=width_B * 2)
  777. JD_Input.grid(
  778. column=a_x +
  779. 1,
  780. row=a_y,
  781. columnspan=2,
  782. sticky=tkinter.E +
  783. tkinter.W)
  784. a_y += 1
  785. tkinter.Label(
  786. top,
  787. text='函数名字:',
  788. bg=bg,
  789. fg=fg,
  790. font=FONT,
  791. width=width_B,
  792. height=height_B).grid(
  793. column=a_x,
  794. row=a_y) # 设置说明
  795. FuncName_Input = tkinter.Entry(top, width=width_B * 2)
  796. FuncName_Input.grid(
  797. column=a_x +
  798. 1,
  799. row=a_y,
  800. columnspan=2,
  801. sticky=tkinter.E +
  802. tkinter.W)
  803. a_y += 1
  804. tkinter.Label(
  805. top,
  806. text='函数视图:',
  807. bg=bg,
  808. fg=fg,
  809. font=FONT,
  810. width=width_B,
  811. height=height_B).grid(
  812. column=a_x,
  813. row=a_y) # 设置说明
  814. FuncView_Input = tkinter.Entry(top, width=width_B * 2)
  815. FuncView_Input.grid(
  816. column=a_x +
  817. 1,
  818. row=a_y,
  819. columnspan=2,
  820. sticky=tkinter.E +
  821. tkinter.W)
  822. global a_MR, a_start, a_end, a_kd
  823. a_y += 1
  824. tkinter.Label(
  825. top,
  826. text='常量a默认值:',
  827. bg=bg,
  828. fg=fg,
  829. font=FONT,
  830. width=width_B,
  831. height=height_B).grid(
  832. column=a_x,
  833. row=a_y) # 设置说明
  834. a_MR = tkinter.Entry(top, width=width_B * 2)
  835. a_MR.grid(
  836. column=a_x +
  837. 1,
  838. row=a_y,
  839. columnspan=2,
  840. sticky=tkinter.E +
  841. tkinter.W)
  842. a_y += 1
  843. tkinter.Label(
  844. top,
  845. text='常量a起点:',
  846. bg=bg,
  847. fg=fg,
  848. font=FONT,
  849. width=width_B,
  850. height=height_B).grid(
  851. column=a_x,
  852. row=a_y) # 设置说明
  853. a_start = tkinter.Entry(top, width=width_B * 2)
  854. a_start.grid(
  855. column=a_x +
  856. 1,
  857. row=a_y,
  858. columnspan=2,
  859. sticky=tkinter.E +
  860. tkinter.W)
  861. a_y += 1
  862. tkinter.Label(
  863. top,
  864. text='常量a终点:',
  865. bg=bg,
  866. fg=fg,
  867. font=FONT,
  868. width=width_B,
  869. height=height_B).grid(
  870. column=a_x,
  871. row=a_y) # 设置说明
  872. a_end = tkinter.Entry(top, width=width_B * 2)
  873. a_end.grid(
  874. column=a_x +
  875. 1,
  876. row=a_y,
  877. columnspan=2,
  878. sticky=tkinter.E +
  879. tkinter.W)
  880. a_y += 1
  881. tkinter.Label(
  882. top,
  883. text='常量a跨度:',
  884. bg=bg,
  885. fg=fg,
  886. font=FONT,
  887. width=width_B,
  888. height=height_B).grid(
  889. column=a_x,
  890. row=a_y) # 设置说明
  891. a_kd = tkinter.Entry(top, width=width_B * 2)
  892. a_kd.grid(
  893. column=a_x +
  894. 1,
  895. row=a_y,
  896. columnspan=2,
  897. sticky=tkinter.E +
  898. tkinter.W)
  899. a_y += 1
  900. tkinter.Button(
  901. top,
  902. bg=bbg,
  903. fg=fg,
  904. text='应用函数',
  905. command=set_function,
  906. font=FONT,
  907. width=width_B,
  908. height=height_B).grid(
  909. column=a_x,
  910. row=a_y,
  911. sticky=tkinter.E +
  912. tkinter.W) # 添加函数
  913. tkinter.Button(
  914. top,
  915. bg=bbg,
  916. fg=fg,
  917. text='绘制图像',
  918. command=function_drawing,
  919. font=FONT,
  920. width=width_B,
  921. height=height_B).grid(
  922. column=a_x +
  923. 1,
  924. row=a_y,
  925. sticky=tkinter.E +
  926. tkinter.W)
  927. tkinter.Button(
  928. top,
  929. bg=bbg,
  930. fg=fg,
  931. text='性质预测',
  932. command=property_prediction,
  933. font=FONT,
  934. width=width_B,
  935. height=height_B).grid(
  936. column=a_x +
  937. 2,
  938. row=a_y,
  939. sticky=tkinter.E +
  940. tkinter.W) # 添加函数
  941. global XZ_BOX, XZ_JD
  942. a_y += 1
  943. tkinter.Label(
  944. top,
  945. text='预测精度:',
  946. bg=bg,
  947. fg=fg,
  948. font=FONT,
  949. width=width_B,
  950. height=height_B).grid(
  951. column=a_x,
  952. row=a_y) # 设置说明
  953. XZ_JD = tkinter.Entry(top, width=width_B * 2)
  954. XZ_JD.grid(
  955. column=a_x +
  956. 1,
  957. row=a_y,
  958. columnspan=2,
  959. sticky=tkinter.E +
  960. tkinter.W)
  961. a_y += 1
  962. # 显示函数的xy
  963. XZ_BOX = tkinter.Listbox(top, width=width_B * 3) # 暂时不启用多选
  964. XZ_BOX.grid(
  965. column=a_x,
  966. row=a_y,
  967. columnspan=3,
  968. rowspan=9,
  969. sticky=tkinter.S +
  970. tkinter.N +
  971. tkinter.E +
  972. tkinter.W)
  973. a_x += 3
  974. tkinter.Label(
  975. top,
  976. text='',
  977. bg=bg,
  978. fg=fg,
  979. font=FONT,
  980. width=1).grid(
  981. column=a_x,
  982. row=0) # 设置说明
  983. # 第二排的开始
  984. global XZ_Input, XZstart_Input, XZend_Input, XZkd_Input, YZ_Input, YZstart_Input, YZend_Input, YZkd_Input
  985. global Xlimstart_Input, Xlimend_Input, Ylimstart_Input, Ylimend_Input
  986. a_x += 1
  987. a_y = 0
  988. tkinter.Label(
  989. top,
  990. text='X轴刻度声明:',
  991. bg=bg,
  992. fg=fg,
  993. font=FONT,
  994. width=width_B,
  995. height=height_B).grid(
  996. column=a_x,
  997. row=a_y) # 设置说明
  998. XZ_Input = tkinter.Entry(top, width=width_B * 2)
  999. XZ_Input.grid(
  1000. column=a_x +
  1001. 1,
  1002. row=a_y,
  1003. columnspan=2,
  1004. sticky=tkinter.E +
  1005. tkinter.W)
  1006. a_y += 1
  1007. tkinter.Label(
  1008. top,
  1009. text='X轴刻度起点:',
  1010. bg=bg,
  1011. fg=fg,
  1012. font=FONT,
  1013. width=width_B,
  1014. height=height_B).grid(
  1015. column=a_x,
  1016. row=a_y) # 设置说明
  1017. XZstart_Input = tkinter.Entry(top, width=width_B * 2)
  1018. XZstart_Input.grid(
  1019. column=a_x +
  1020. 1,
  1021. row=a_y,
  1022. columnspan=2,
  1023. sticky=tkinter.E +
  1024. tkinter.W)
  1025. a_y += 1
  1026. tkinter.Label(
  1027. top,
  1028. text='X轴刻度终点:',
  1029. bg=bg,
  1030. fg=fg,
  1031. font=FONT,
  1032. width=width_B,
  1033. height=height_B).grid(
  1034. column=a_x,
  1035. row=a_y) # 设置说明
  1036. XZend_Input = tkinter.Entry(top, width=width_B * 2)
  1037. XZend_Input.grid(
  1038. column=a_x +
  1039. 1,
  1040. row=a_y,
  1041. columnspan=2,
  1042. sticky=tkinter.E +
  1043. tkinter.W)
  1044. a_y += 1
  1045. tkinter.Label(
  1046. top,
  1047. text='X轴刻度间隔:',
  1048. bg=bg,
  1049. fg=fg,
  1050. font=FONT,
  1051. width=width_B,
  1052. height=height_B).grid(
  1053. column=a_x,
  1054. row=a_y) # 设置说明
  1055. XZkd_Input = tkinter.Entry(top, width=width_B * 2)
  1056. XZkd_Input.grid(
  1057. column=a_x +
  1058. 1,
  1059. row=a_y,
  1060. columnspan=2,
  1061. sticky=tkinter.E +
  1062. tkinter.W)
  1063. a_y += 1
  1064. tkinter.Label(
  1065. top,
  1066. text='Y轴刻度声明:',
  1067. bg=bg,
  1068. fg=fg,
  1069. font=FONT,
  1070. width=width_B,
  1071. height=height_B).grid(
  1072. column=a_x,
  1073. row=a_y) # 设置说明
  1074. YZ_Input = tkinter.Entry(top, width=width_B * 2)
  1075. YZ_Input.grid(
  1076. column=a_x +
  1077. 1,
  1078. row=a_y,
  1079. columnspan=2,
  1080. sticky=tkinter.E +
  1081. tkinter.W)
  1082. a_y += 1
  1083. tkinter.Label(
  1084. top,
  1085. text='Y轴刻度起点:',
  1086. bg=bg,
  1087. fg=fg,
  1088. font=FONT,
  1089. width=width_B,
  1090. height=height_B).grid(
  1091. column=a_x,
  1092. row=a_y) # 设置说明
  1093. YZstart_Input = tkinter.Entry(top, width=width_B * 2)
  1094. YZstart_Input.grid(
  1095. column=a_x +
  1096. 1,
  1097. row=a_y,
  1098. columnspan=2,
  1099. sticky=tkinter.E +
  1100. tkinter.W)
  1101. a_y += 1
  1102. tkinter.Label(
  1103. top,
  1104. text='Y轴刻度终点:',
  1105. bg=bg,
  1106. fg=fg,
  1107. font=FONT,
  1108. width=width_B,
  1109. height=height_B).grid(
  1110. column=a_x,
  1111. row=a_y) # 设置说明
  1112. YZend_Input = tkinter.Entry(top, width=width_B * 2)
  1113. YZend_Input.grid(
  1114. column=a_x +
  1115. 1,
  1116. row=a_y,
  1117. columnspan=2,
  1118. sticky=tkinter.E +
  1119. tkinter.W)
  1120. a_y += 1
  1121. tkinter.Label(
  1122. top,
  1123. text='Y轴刻度间隔:',
  1124. bg=bg,
  1125. fg=fg,
  1126. font=FONT,
  1127. width=width_B,
  1128. height=height_B).grid(
  1129. column=a_x,
  1130. row=a_y) # 设置说明
  1131. YZkd_Input = tkinter.Entry(top, width=width_B * 2)
  1132. YZkd_Input.grid(
  1133. column=a_x +
  1134. 1,
  1135. row=a_y,
  1136. columnspan=2,
  1137. sticky=tkinter.E +
  1138. tkinter.W)
  1139. a_y += 1
  1140. tkinter.Label(
  1141. top,
  1142. text='X轴显示起点:',
  1143. bg=bg,
  1144. fg=fg,
  1145. font=FONT,
  1146. width=width_B,
  1147. height=height_B).grid(
  1148. column=a_x,
  1149. row=a_y) # 设置说明
  1150. Xlimstart_Input = tkinter.Entry(top, width=width_B * 2)
  1151. Xlimstart_Input.grid(
  1152. column=a_x +
  1153. 1,
  1154. row=a_y,
  1155. columnspan=2,
  1156. sticky=tkinter.E +
  1157. tkinter.W)
  1158. a_y += 1
  1159. tkinter.Label(
  1160. top,
  1161. text='X轴显示终点:',
  1162. bg=bg,
  1163. fg=fg,
  1164. font=FONT,
  1165. width=width_B,
  1166. height=height_B).grid(
  1167. column=a_x,
  1168. row=a_y) # 设置说明
  1169. Xlimend_Input = tkinter.Entry(top, width=width_B * 2)
  1170. Xlimend_Input.grid(
  1171. column=a_x +
  1172. 1,
  1173. row=a_y,
  1174. columnspan=2,
  1175. sticky=tkinter.E +
  1176. tkinter.W)
  1177. a_y += 1
  1178. tkinter.Label(
  1179. top,
  1180. text='Y轴显示起点:',
  1181. bg=bg,
  1182. fg=fg,
  1183. font=FONT,
  1184. width=width_B,
  1185. height=height_B).grid(
  1186. column=a_x,
  1187. row=a_y) # 设置说明
  1188. Ylimstart_Input = tkinter.Entry(top, width=width_B * 2)
  1189. Ylimstart_Input.grid(
  1190. column=a_x +
  1191. 1,
  1192. row=a_y,
  1193. columnspan=2,
  1194. sticky=tkinter.E +
  1195. tkinter.W)
  1196. a_y += 1
  1197. tkinter.Label(
  1198. top,
  1199. text='Y轴显示终点:',
  1200. bg=bg,
  1201. fg=fg,
  1202. font=FONT,
  1203. width=width_B,
  1204. height=height_B).grid(
  1205. column=a_x,
  1206. row=a_y) # 设置说明
  1207. Ylimend_Input = tkinter.Entry(top, width=width_B * 2)
  1208. Ylimend_Input.grid(
  1209. column=a_x +
  1210. 1,
  1211. row=a_y,
  1212. columnspan=2,
  1213. sticky=tkinter.E +
  1214. tkinter.W)
  1215. global ZL_Input
  1216. a_y += 1
  1217. tkinter.Label(
  1218. top,
  1219. text='帧率(帧/ms):',
  1220. bg=bg,
  1221. fg=fg,
  1222. font=FONT,
  1223. width=width_B,
  1224. height=height_B).grid(
  1225. column=a_x,
  1226. row=a_y) # 设置说明
  1227. ZL_Input = tkinter.Entry(top, width=width_B * 2)
  1228. ZL_Input.grid(
  1229. column=a_x +
  1230. 1,
  1231. row=a_y,
  1232. columnspan=2,
  1233. sticky=tkinter.E +
  1234. tkinter.W)
  1235. global Point_Draw, Best_Draw, Test_Draw
  1236. a_y += 1
  1237. Point_Draw = tkinter.IntVar()
  1238. Best_Draw = tkinter.IntVar()
  1239. Test_Draw = tkinter.IntVar()
  1240. tkinter.Checkbutton(
  1241. top,
  1242. bg=bg,
  1243. fg=fg,
  1244. activebackground=bg,
  1245. activeforeground=fg,
  1246. selectcolor=bg,
  1247. text="显示记忆点",
  1248. variable=Point_Draw).grid(
  1249. column=a_x,
  1250. row=a_y,
  1251. sticky=tkinter.E +
  1252. tkinter.W)
  1253. tkinter.Checkbutton(
  1254. top,
  1255. bg=bg,
  1256. fg=fg,
  1257. activebackground=bg,
  1258. activeforeground=fg,
  1259. selectcolor=bg,
  1260. text="显示最值",
  1261. variable=Best_Draw).grid(
  1262. column=a_x +
  1263. 1,
  1264. row=a_y,
  1265. sticky=tkinter.E +
  1266. tkinter.W)
  1267. tkinter.Checkbutton(
  1268. top,
  1269. bg=bg,
  1270. fg=fg,
  1271. activebackground=bg,
  1272. activeforeground=fg,
  1273. selectcolor=bg,
  1274. text="显示文字",
  1275. variable=Test_Draw).grid(
  1276. column=a_x +
  1277. 2,
  1278. row=a_y,
  1279. sticky=tkinter.E +
  1280. tkinter.W)
  1281. global News_BOX, Draw_BOX
  1282. a_y += 1
  1283. # 显示函数的xy
  1284. Draw_BOX = tkinter.Listbox(
  1285. top,
  1286. width=width_B *
  1287. 3,
  1288. height=height_B *
  1289. 4) # 暂时不启用多选
  1290. Draw_BOX.grid(
  1291. column=a_x,
  1292. row=a_y,
  1293. columnspan=3,
  1294. rowspan=3,
  1295. sticky=tkinter.S +
  1296. tkinter.N +
  1297. tkinter.E +
  1298. tkinter.W)
  1299. Draw_BOX.insert(tkinter.END,
  1300. *['笛卡尔坐标系静态图像(默认)',
  1301. '矩形坐标系静态图像',
  1302. '笛卡尔坐标系动态图像',
  1303. '矩形坐标系动态图像',
  1304. '笛卡尔坐标系静态图像(无线框)',
  1305. '矩形坐标系静态图像(无线框)',
  1306. '笛卡尔坐标系动态图像(无线框)',
  1307. '矩形坐标系动态图像(无线框)',
  1308. '笛卡尔坐标系动态画图',
  1309. '矩形坐标系动态画图'])
  1310. a_y += 3
  1311. # 显示函数的xy
  1312. News_BOX = tkinter.Listbox(
  1313. top,
  1314. width=width_B *
  1315. 3,
  1316. height=height_B *
  1317. 2) # 暂时不启用多选
  1318. News_BOX.grid(
  1319. column=a_x,
  1320. row=a_y,
  1321. columnspan=3,
  1322. rowspan=2,
  1323. sticky=tkinter.S +
  1324. tkinter.N +
  1325. tkinter.E +
  1326. tkinter.W)
  1327. a_x += 3
  1328. tkinter.Label(
  1329. top,
  1330. text='',
  1331. bg=bg,
  1332. fg=fg,
  1333. font=FONT,
  1334. width=1).grid(
  1335. column=a_x,
  1336. row=0) # 设置说明
  1337. global Ycul_Input, Xcul_Input, Xcul_CS, Xcul_TD_Input, Xcul_TD_CS, R_cul
  1338. a_x += 1
  1339. a_y = 0
  1340. tkinter.Label(
  1341. top,
  1342. text='计算(y):',
  1343. bg=bg,
  1344. fg=fg,
  1345. font=FONT,
  1346. width=width_B,
  1347. height=height_B).grid(
  1348. column=a_x,
  1349. row=a_y) # 设置说明
  1350. Ycul_Input = tkinter.Entry(top, width=width_B * 2)
  1351. Ycul_Input.grid(
  1352. column=a_x +
  1353. 1,
  1354. row=a_y,
  1355. columnspan=2,
  1356. sticky=tkinter.E +
  1357. tkinter.W)
  1358. a_y += 1
  1359. tkinter.Label(
  1360. top,
  1361. text='二分法计算(x):',
  1362. bg=bg,
  1363. fg=fg,
  1364. font=FONT,
  1365. width=width_B,
  1366. height=height_B).grid(
  1367. column=a_x,
  1368. row=a_y) # 设置说明
  1369. Xcul_Input = tkinter.Entry(top, width=width_B * 2)
  1370. Xcul_Input.grid(
  1371. column=a_x +
  1372. 1,
  1373. row=a_y,
  1374. columnspan=2,
  1375. sticky=tkinter.E +
  1376. tkinter.W)
  1377. Xcul_CS = [] # 二分法参数输入
  1378. name_List = [
  1379. '最大迭代数',
  1380. '计算精度',
  1381. '最值允许偏移量',
  1382. '零点最小间隔',
  1383. '减少计算',
  1384. '允许梯度计算',
  1385. '最大扩张深度',
  1386. '扩张限制',
  1387. '扩张偏移量',
  1388. '开启二级验证',
  1389. '二级验证程度']
  1390. for i in range(11):
  1391. a_y += 1
  1392. Xcul_CS.append(tkinter.StringVar())
  1393. tkinter.Label(
  1394. top,
  1395. bg=bg,
  1396. fg=fg,
  1397. text=name_List[i] + ':',
  1398. font=FONT,
  1399. width=width_B,
  1400. height=height_B).grid(
  1401. column=a_x,
  1402. row=a_y) # 设置说明
  1403. tkinter.Entry(top,
  1404. width=width_B * 2,
  1405. textvariable=Xcul_CS[-1]).grid(column=a_x + 1,
  1406. row=a_y,
  1407. columnspan=2,
  1408. sticky=tkinter.E + tkinter.W)
  1409. a_y += 1
  1410. tkinter.Label(
  1411. top,
  1412. text='梯度法计算(x):',
  1413. bg=bg,
  1414. fg=fg,
  1415. font=FONT,
  1416. width=width_B,
  1417. height=height_B).grid(
  1418. column=a_x,
  1419. row=a_y) # 设置说明
  1420. Xcul_TD_Input = tkinter.Entry(top, width=width_B * 2)
  1421. Xcul_TD_Input.grid(
  1422. column=a_x +
  1423. 1,
  1424. row=a_y,
  1425. columnspan=2,
  1426. sticky=tkinter.E +
  1427. tkinter.W)
  1428. Xcul_TD_CS = [] # 梯度法法参数输入
  1429. name_List = ['梯度起点', '梯度终点', '计算深度', '计算精度']
  1430. for i in range(4):
  1431. a_y += 1
  1432. Xcul_TD_CS.append(tkinter.StringVar())
  1433. tkinter.Label(
  1434. top,
  1435. bg=bg,
  1436. fg=fg,
  1437. text=name_List[i] + ':',
  1438. font=FONT,
  1439. width=width_B,
  1440. height=height_B).grid(
  1441. column=a_x,
  1442. row=a_y) # 设置说明
  1443. tkinter.Entry(top,
  1444. width=width_B * 2,
  1445. textvariable=Xcul_TD_CS[-1]).grid(column=a_x + 1,
  1446. row=a_y,
  1447. columnspan=2,
  1448. sticky=tkinter.E + tkinter.W)
  1449. a_y += 1
  1450. tkinter.Label(
  1451. top,
  1452. text='',
  1453. bg=bg,
  1454. fg=fg,
  1455. height=1).grid(
  1456. column=1,
  1457. row=a_y) # 底部
  1458. a_x += 3
  1459. tkinter.Label(
  1460. top,
  1461. text='',
  1462. bg=bg,
  1463. fg=fg,
  1464. font=FONT,
  1465. width=1).grid(
  1466. column=a_x,
  1467. row=0) # 设置说明
  1468. global Xcul_DS_Input, DScul_Input, DScul_JD_Input
  1469. a_x += 1
  1470. a_y = 0
  1471. tkinter.Label(
  1472. top,
  1473. text='代数法计算(x):',
  1474. bg=bg,
  1475. fg=fg,
  1476. font=FONT,
  1477. width=width_B,
  1478. height=height_B).grid(
  1479. column=a_x,
  1480. row=a_y) # 设置说明
  1481. Xcul_DS_Input = tkinter.Entry(top, width=width_B * 2)
  1482. Xcul_DS_Input.grid(
  1483. column=a_x +
  1484. 1,
  1485. row=a_y,
  1486. columnspan=2,
  1487. sticky=tkinter.E +
  1488. tkinter.W)
  1489. a_y += 1
  1490. tkinter.Label(
  1491. top,
  1492. text='求(x)导数:',
  1493. bg=bg,
  1494. fg=fg,
  1495. font=FONT,
  1496. width=width_B,
  1497. height=height_B).grid(
  1498. column=a_x,
  1499. row=a_y) # 设置说明
  1500. DScul_Input = tkinter.Entry(top, width=width_B * 2)
  1501. DScul_Input.grid(
  1502. column=a_x +
  1503. 1,
  1504. row=a_y,
  1505. columnspan=2,
  1506. sticky=tkinter.E +
  1507. tkinter.W)
  1508. a_y += 1
  1509. tkinter.Label(
  1510. top,
  1511. text='逼近求导精度:',
  1512. bg=bg,
  1513. fg=fg,
  1514. font=FONT,
  1515. width=width_B,
  1516. height=height_B).grid(
  1517. column=a_x,
  1518. row=a_y) # 设置说明
  1519. DScul_JD_Input = tkinter.Entry(top, width=width_B * 2)
  1520. DScul_JD_Input.grid(
  1521. column=a_x +
  1522. 1,
  1523. row=a_y,
  1524. columnspan=2,
  1525. sticky=tkinter.E +
  1526. tkinter.W)
  1527. a_y += 1
  1528. tkinter.Button(
  1529. top,
  1530. bg=bbg,
  1531. fg=fg,
  1532. text='计算(y)',
  1533. command=calculate,
  1534. font=FONT,
  1535. width=width_B,
  1536. height=height_B).grid(
  1537. column=a_x,
  1538. row=a_y) # 设置说明
  1539. tkinter.Button(
  1540. top,
  1541. bg=bbg,
  1542. fg=fg,
  1543. text='二分法计算(x)',
  1544. command=dichotomy,
  1545. font=FONT,
  1546. width=width_B,
  1547. height=height_B).grid(
  1548. column=a_x + 1,
  1549. row=a_y)
  1550. tkinter.Button(
  1551. top,
  1552. bg=bbg,
  1553. fg=fg,
  1554. text='梯度法计算(x)',
  1555. command=gradient_method_calculation,
  1556. font=FONT,
  1557. width=width_B,
  1558. height=height_B).grid(
  1559. column=a_x + 2,
  1560. row=a_y)
  1561. a_y += 1
  1562. tkinter.Button(
  1563. top,
  1564. bg=bbg,
  1565. fg=fg,
  1566. text='代数法计算',
  1567. command=sympy_calculation_x,
  1568. font=FONT,
  1569. width=width_B,
  1570. height=height_B).grid(
  1571. column=a_x,
  1572. row=a_y,
  1573. sticky=tkinter.N +
  1574. tkinter.E +
  1575. tkinter.W)
  1576. tkinter.Button(
  1577. top,
  1578. bg=bbg,
  1579. fg=fg,
  1580. text='逼近法导数计算',
  1581. command=approximation,
  1582. font=FONT,
  1583. width=width_B,
  1584. height=height_B).grid(
  1585. column=a_x +
  1586. 1,
  1587. row=a_y,
  1588. sticky=tkinter.N +
  1589. tkinter.E +
  1590. tkinter.W)
  1591. tkinter.Button(
  1592. top,
  1593. bg=bbg,
  1594. fg=fg,
  1595. text='导数计算',
  1596. command=function_differentiation,
  1597. font=FONT,
  1598. width=width_B,
  1599. height=height_B).grid(
  1600. column=a_x +
  1601. 2,
  1602. row=a_y,
  1603. sticky=tkinter.N +
  1604. tkinter.E +
  1605. tkinter.W)
  1606. a_y += 1
  1607. k = 5
  1608. R_cul = tkinter.Listbox(top, height=height_B * (k - 1)) # 暂时不启用多选
  1609. R_cul.grid(
  1610. column=a_x,
  1611. row=a_y,
  1612. columnspan=3,
  1613. rowspan=k,
  1614. sticky=tkinter.N +
  1615. tkinter.E +
  1616. tkinter.W)
  1617. global YC_Input, YC_BOX
  1618. a_y += k - 1
  1619. tkinter.Label(
  1620. top,
  1621. text='性质预测值:',
  1622. bg=bg,
  1623. fg=fg,
  1624. font=FONT,
  1625. width=width_B,
  1626. height=height_B).grid(
  1627. column=a_x,
  1628. row=a_y,
  1629. sticky=tkinter.N +
  1630. tkinter.S) # 设置说明
  1631. YC_Input = tkinter.Entry(top, width=width_B * 2)
  1632. YC_Input.grid(
  1633. column=a_x +
  1634. 1,
  1635. row=a_y,
  1636. columnspan=2,
  1637. sticky=tkinter.E +
  1638. tkinter.W)
  1639. a_y += 1
  1640. tkinter.Button(
  1641. top,
  1642. bg=bbg,
  1643. fg=fg,
  1644. text='周期性',
  1645. command=check_periodic,
  1646. font=FONT,
  1647. width=width_B,
  1648. height=height_B).grid(
  1649. column=a_x,
  1650. row=a_y,
  1651. sticky=tkinter.N +
  1652. tkinter.E +
  1653. tkinter.W)
  1654. tkinter.Button(
  1655. top,
  1656. bg=bbg,
  1657. fg=fg,
  1658. text='对称轴',
  1659. command=check_symmetry_axis,
  1660. font=FONT,
  1661. width=width_B,
  1662. height=height_B).grid(
  1663. column=a_x +
  1664. 1,
  1665. row=a_y,
  1666. sticky=tkinter.N +
  1667. tkinter.E +
  1668. tkinter.W)
  1669. tkinter.Button(
  1670. top,
  1671. bg=bbg,
  1672. fg=fg,
  1673. text='对称中心',
  1674. command=check_center_of_symmetry,
  1675. font=FONT,
  1676. width=width_B,
  1677. height=height_B).grid(
  1678. column=a_x +
  1679. 2,
  1680. row=a_y,
  1681. sticky=tkinter.N +
  1682. tkinter.E +
  1683. tkinter.W)
  1684. a_y += 1
  1685. tkinter.Button(
  1686. top,
  1687. bg=bbg,
  1688. fg=fg,
  1689. text='单调性',
  1690. command=check_monotonic,
  1691. font=FONT,
  1692. width=width_B,
  1693. height=height_B).grid(
  1694. column=a_x,
  1695. row=a_y,
  1696. columnspan=3,
  1697. sticky=tkinter.N +
  1698. tkinter.E +
  1699. tkinter.W)
  1700. a_y += 1
  1701. # 显示函数的xy
  1702. YC_BOX = tkinter.Listbox(
  1703. top,
  1704. width=width_B *
  1705. 3,
  1706. height=height_B *
  1707. 5) # 暂时不启用多选
  1708. YC_BOX.grid(
  1709. column=a_x,
  1710. row=a_y,
  1711. columnspan=3,
  1712. rowspan=6,
  1713. sticky=tkinter.S +
  1714. tkinter.N +
  1715. tkinter.E +
  1716. tkinter.W)
  1717. a_x += 3
  1718. tkinter.Label(
  1719. top,
  1720. text='',
  1721. bg=bg,
  1722. fg=fg,
  1723. font=FONT,
  1724. width=1).grid(
  1725. column=a_x,
  1726. row=0) # 设置说明
  1727. a_x += 1
  1728. a_y = 0
  1729. tkinter.Button(
  1730. top,
  1731. bg=bbg,
  1732. fg=fg,
  1733. text='生成表格',
  1734. command=to_sheet,
  1735. font=FONT,
  1736. width=width_B * 2,
  1737. height=height_B).grid(
  1738. column=a_x,
  1739. row=a_y,
  1740. columnspan=2)
  1741. tkinter.Button(
  1742. top,
  1743. bg=bbg,
  1744. fg=fg,
  1745. text='导出表格',
  1746. command=save_to_csv,
  1747. font=FONT,
  1748. width=width_B,
  1749. height=height_B).grid(
  1750. column=a_x + 2,
  1751. row=a_y)
  1752. global Pr_BOX
  1753. a_y += 1
  1754. # 显示函数的xy
  1755. Pr_BOX = tkinter.Listbox(top, width=width_B * 3) # 暂时不启用多选
  1756. Pr_BOX.grid(
  1757. column=a_x,
  1758. row=a_y,
  1759. columnspan=3,
  1760. rowspan=17,
  1761. sticky=tkinter.S +
  1762. tkinter.N +
  1763. tkinter.E +
  1764. tkinter.W)
  1765. output_prompt('加载完毕')
  1766. tkinter.mainloop()