12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673 |
- from __future__ import division # 让/恢复为除法
- import random
- import tkinter
- import tkinter.messagebox
- import sympy
- from matplotlib import pyplot as plt
- from matplotlib import rcParams
- from matplotlib.animation import FuncAnimation
- from funcsystem.controller import ExpFunc as ExpFunc
- from newtkinter import asksaveasfilename
- func = None
- fig = None
- prompt_num = 0
- line_style = {
- "实线": "-",
- "短横线": "--",
- "点划线": "-,",
- "虚线": ":",
- "点标记": ".",
- "圆标记": "o",
- "倒三角": "v",
- "正三角": "^",
- "左三角": "<",
- "下箭头": "1",
- "上箭头": "2",
- "左箭头": "3",
- "右箭头": "4",
- "正方形": "s",
- "五边形": "p",
- "星形": "*",
- "六边形": "h",
- "六边形2": "H",
- "+号": "+",
- "X标记": "x",
- } # 函数样式翻译表
- point_style = ["g", "r", "c", "m", "y", "k"]
- SCREEN = tkinter.Tk()
- bg_color = "#FFFAFA" # 主颜色
- botton_color = "#FFFAFA" # 按钮颜色
- word_color = "#000000" # 文字颜色
- gui_width = 13 # 标准宽度
- gui_height = 2
- row = 0
- column = 1
- class UIAPI:
- @staticmethod
- def dichotomy_gui():
- parameters = [100, 0.0001, 0.1, 0.5, False, True, 1000, 0.1, 0.1, False, None]
- for i in range(11):
- try:
- if i in (4, 5, 9):
- a = dicon_parameters[i].get()
- else:
- a = float(dicon_parameters[i].get())
- parameters[i] = a
- except BaseException:
- pass
- return parameters
- @staticmethod
- def output_prompt_gui(news):
- global prompt_box, prompt_num, SCREEN
- prompt_num += 1
- news = str(news)
- prompt_box.insert(0, news + f"({prompt_num})")
- SCREEN.update()
- @staticmethod
- def set_func_gui():
- new_func = func_exp.get().replace(" ", "")
- if new_func == "":
- API.output_prompt_gui("应用失败")
- raise Exception
- default_value = [-10, 10, 0.1, 2, 1, -10, 10, 1]
- get = [
- start_definition,
- end_definition,
- span_definition,
- accuracy,
- default_a,
- start_a,
- end_a,
- span_a,
- ]
- # 参数的处理
- try:
- span_str = span_definition.get().replace(" ", "")
- if span_str[0] == "H":
- domain = {
- "Pi": sympy.pi,
- "e": sympy.E,
- "log": sympy.log,
- "sin": sympy.sin,
- "cos": sympy.cos,
- "tan": sympy.tan,
- "cot": lambda x: 1 / sympy.tan(x),
- "csc": lambda x: 1 / sympy.sin(x),
- "sec": lambda x: 1 / sympy.cos(x),
- "sinh": sympy.sinh,
- "cosh": sympy.cosh,
- "tanh": sympy.tanh,
- "asin": sympy.asin,
- "acos": sympy.acos,
- "atan": sympy.atan,
- }
- span = eval(span_str[1:], domain)
- else:
- raise Exception
- except BaseException:
- span = None
- for i in range(8):
- try:
- default_value[i] = float(get[i].get())
- except BaseException:
- pass
- if span is not None:
- default_value[2] = span
- # View的处理
- style_str = func_style.get().split("#")
- try:
- if style_str[0] not in point_style:
- style_str[0] = "b"
- line_style_str = line_style.get(style_str[1], "-")
- except BaseException:
- style_str = ["", ""]
- style_str[0] = random.choice(point_style)
- line_style_str = "-"
- style = style_str[0] + line_style_str
- # Name的处理
- name = func_name.get().replace(" ", "")
- if name == "":
- name = new_func
- return [new_func, name, style]+default_value
- @staticmethod
- def get_y_value_gui():
- return y_value.get().split(",")
- @staticmethod
- def update_prediction_box_gui(answer):
- prediction_box.delete(0, tkinter.END)
- prediction_box.insert(tkinter.END, *answer)
- @staticmethod
- def get_projection_value_gui():
- return projection_value.get
- @staticmethod
- def get_proximity_accuracy_gui():
- return proximity_accuracy.get()
- @staticmethod
- def get_x_value_derivation_gui():
- return x_value_derivation.get().split(",")
- @staticmethod
- def get_y_value_symbol_gui():
- return y_value_symbol.get().split(",")
- @staticmethod
- def get_x_value_gui():
- return x_value.get().split(",")
- @staticmethod
- def update_result_box_gui(answer):
- result_box.delete(0, tkinter.END) # 清空
- result_box.insert(tkinter.END, *answer)
- @staticmethod
- def get_y_value_gradient_gui():
- return y_value_gradient.get()
- @staticmethod
- def askokcancel_gui(message):
- return tkinter.messagebox.askokcancel("提示", message)
- @staticmethod
- def add_projection_box_gui(result):
- projection_box.insert(tkinter.END, result)
- @staticmethod
- def update_sheet_box_gui(sheet):
- sheet_box.delete(0, tkinter.END)
- sheet_box.insert(tkinter.END, *sheet)
- @staticmethod
- def get_save_dir_gui():
- return asksaveasfilename(title="选择导出位置", filetypes=[("CSV", ".csv")])
- class API(UIAPI):
- @staticmethod
- def type_selection(sequence, type_=float, convert=True): # Float筛选系统
- x = []
- for i in sequence:
- try:
- if type_(i) == type_(0) and convert:
- continue
- x.append(type_(i))
- except ValueError:
- pass
- return x
- @staticmethod
- def save_to_csv(): # 导出CSV
- try:
- if not func.save_csv(API.get_save_dir_gui()):
- raise Exception
- API.output_prompt_gui("CSV导出成功")
- except BaseException:
- API.output_prompt_gui("CSV导出失败")
- @staticmethod
- def save_to_sheet(): # 生成表格
- try:
- API.update_sheet_box_gui(func.return_list())
- API.output_prompt_gui("表格创建成功")
- except BaseException:
- API.output_prompt_gui("无法创建表格")
- @staticmethod
- def sympy_computing(exp_str) -> tuple:
- try:
- named_domain = {
- "Pi": sympy.pi,
- "e": sympy.E,
- "log": sympy.log,
- "sin": sympy.sin,
- "cos": sympy.cos,
- "tan": sympy.tan,
- "cot": lambda x: 1 / sympy.tan(x),
- "csc": lambda x: 1 / sympy.sin(x),
- "sec": lambda x: 1 / sympy.cos(x),
- "sinh": sympy.sinh,
- "cosh": sympy.cosh,
- "tanh": sympy.tanh,
- "asin": sympy.asin,
- "acos": sympy.acos,
- "atan": sympy.atan,
- }
- answer = eval(exp_str, named_domain)
- return answer, True
- except BaseException:
- return None, False
- @staticmethod
- def computing_gui():
- accuracy, must = API.sympy_computing(prediction_accuracy.get())
- return accuracy
- @staticmethod
- def confirmation_expression(c):
- get = API.sympy_computing(c)
- if not get[1]:
- return c
- return get[0]
- @staticmethod
- def check_center_of_symmetry():
- accuracy = API.computing_gui()
- try:
- result = func.check_symmetry_center(
- API.confirmation_expression(API.get_projection_value_gui()), API.output_prompt_gui, accuracy
- )
- if result[0]:
- API.add_projection_box_gui(result[1])
- API.output_prompt_gui("预测完成")
- else:
- raise Exception
- except BaseException:
- API.output_prompt_gui("预测失败")
- @staticmethod
- def check_symmetry_axis():
- accuracy = API.computing_gui()
- try:
- result = func.check_symmetry_axis(
- API.confirmation_expression(API.get_projection_value_gui()), API.output_prompt_gui, accuracy
- )
- if result[0]:
- API.add_projection_box_gui(result[1])
- API.output_prompt_gui("预测完成")
- else:
- raise Exception
- except BaseException:
- API.output_prompt_gui("预测失败")
- @staticmethod
- def check_periodic():
- accuracy = API.computing_gui()
- try:
- result = func.check_periodic(
- API.confirmation_expression(API.get_projection_value_gui()), API.output_prompt_gui, accuracy
- )
- if result[0]:
- API.add_projection_box_gui(result[1])
- API.output_prompt_gui("预测完成")
- else:
- raise Exception
- except BaseException:
- API.output_prompt_gui("预测失败")
- @staticmethod
- def check_monotonic():
- accuracy = API.computing_gui()
- try:
- result = func.check_monotonic(
- API.get_projection_value_gui(), API.output_prompt_gui, accuracy
- )
- if result[1]:
- API.add_projection_box_gui(result[1])
- API.output_prompt_gui("预测完成")
- else:
- raise Exception
- except BaseException:
- API.output_prompt_gui("预测失败")
- @staticmethod
- def clear_memory():
- try:
- if API.askokcancel_gui(f"确定删除{func}的记忆吗?"):
- API.update_result_box_gui([])
- func.clean_memory()
- API.output_prompt_gui("删除完毕")
- else:
- API.output_prompt_gui("删除取消")
- except BaseException:
- API.output_prompt_gui("删除失败")
- @staticmethod
- def show_hidden_memory(): # 显示xy
- try:
- API.update_result_box_gui([])
- func.hide_or_show()
- API.output_prompt_gui("已清空卡槽")
- except BaseException:
- API.output_prompt_gui("隐藏(显示)失败")
- @staticmethod
- def gradient_method_calculation():
- try:
- API.output_prompt_gui("计算过程程序可能无响应")
- parameters = []
- for i in gradient_parameters:
- parameters.append(i.get())
- API.output_prompt_gui("系统运算中")
- answer = func.gradient_calculation(API.get_y_value_gradient_gui(), *parameters)
- if answer[1] is not None:
- API.update_result_box_gui(answer[0])
- API.output_prompt_gui("系统运算完成")
- else:
- API.output_prompt_gui("系统运算无结果")
- except BaseException:
- API.output_prompt_gui("系统运算失败,请注意参数设置")
- @staticmethod
- def calculate():
- try:
- API.output_prompt_gui("计算过程程序可能无响应")
- answer = func.calculation(API.get_x_value_gui())
- if answer:
- API.output_prompt_gui("系统运算完毕")
- else:
- API.output_prompt_gui("系统运算无结果")
- API.update_result_box_gui(answer)
- except BaseException:
- API.output_prompt_gui("计算失败")
- # raise
- @staticmethod
- def sympy_calculation_x():
- try:
- API.output_prompt_gui("计算过程程序可能无响应")
- answer = []
- for i in API.get_y_value_symbol_gui():
- answer += func.sympy_calculation(i)[0]
- if answer:
- API.output_prompt_gui("系统运算完毕")
- else:
- API.output_prompt_gui("系统运算无结果")
- API.update_result_box_gui(answer)
- except BaseException:
- API.output_prompt_gui("计算失败")
- @staticmethod
- def function_differentiation():
- try:
- API.output_prompt_gui("计算过程程序可能无响应")
- accuracy = API.get_proximity_accuracy_gui()
- answer = []
- for i in API.get_x_value_derivation_gui():
- get = func.derivative(i, accuracy)[0]
- if get is not None:
- answer.append(get)
- if answer:
- API.output_prompt_gui("系统运算完毕")
- else:
- API.output_prompt_gui("系统运算无结果")
- API.update_result_box_gui(answer)
- except IndexError:
- API.output_prompt_gui("计算失败")
- @staticmethod
- def approximation(): # 逼近法
- try:
- API.output_prompt_gui("计算过程程序可能无响应")
- accuracy = API.get_proximity_accuracy_gui()
- answer = []
- for i in API.get_x_value_derivation_gui():
- get = func.derivative(i, accuracy, True)[0]
- if get is not None:
- answer.append(get)
- if answer:
- API.output_prompt_gui("系统运算完毕")
- else:
- API.output_prompt_gui("系统运算无结果")
- API.update_result_box_gui(answer)
- except IndexError:
- API.output_prompt_gui("计算失败")
- @staticmethod
- def dichotomy(): # 二分法
- global dicon_parameters, func, result_box
- try:
- API.output_prompt_gui("计算过程程序可能无响应")
- answer = []
- API.output_prompt_gui("系统运算中")
- for i in API.get_y_value_gui():
- print(i)
- try:
- answer += func.dichotomy(float(i), *API.dichotomy_gui())[0]
- except BaseException:
- pass
- if answer:
- API.output_prompt_gui("系统运算完成")
- else:
- API.output_prompt_gui("系统运算无结果")
- API.update_result_box_gui(answer)
- except BaseException:
- # raise
- API.output_prompt_gui("系统运算失败")
- @staticmethod
- def property_prediction():
- try:
- accuracy = API.computing_gui()
- API.output_prompt_gui("预测过程程序可能无响应")
- answer = func.property_prediction(API.output_prompt_gui, True, accuracy)
- API.update_prediction_box_gui(*answer)
- API.output_prompt_gui("性质预测完成")
- except IndexError:
- API.output_prompt_gui("性质预测失败")
- @staticmethod
- def function_drawing():
- global x_scale, start_x_plot, start_x_polt, span_x_plot, y_scale, start_y_plot, end_y_plot, span_y_plot
- global start_x_limit, end_x_limit, start_y_limit, end_y_limit
- global func, fig, show_point, show_best_value, show_text, plot_type, frame_rate
- try:
- draw_type = plot_type.curselection()[0]
- except BaseException:
- draw_type = 0
- # 画板创造
- API.output_prompt_gui("生成绘制取...")
- fig = plt.figure(num="CoTan函数") # 定义一个图像窗口
- if draw_type in (0, 1, 2, 3, 8, 9):
- plt.grid(True, ls="--") # 显示网格(不能放到后面,因为后面调整成为了笛卡尔坐标系)
- axis = plt.gca()
- text_y = ""
- text_x = ""
- def init():
- nonlocal text_x, text_y
- if draw_type in (0, 2, 4, 6, 8):
- axis.spines["right"].set_color("none")
- axis.spines["top"].set_color("none")
- axis.xaxis.set_ticks_position("bottom")
- axis.yaxis.set_ticks_position("left")
- axis.spines["bottom"].set_position(("data", 0)) # 设置x轴, y轴在(0, 0)的位置
- axis.spines["left"].set_position(("data", 0))
- # 检测x
- try:
- if x_scale.get()[0] == "c": # 如果输入函数cx#-10#10#1#1
- plot_parameter = [
- x_scale.get()[1:],
- start_x_plot.get(),
- start_x_polt.get(),
- span_x_plot.get(),
- 2,
- ] # 第一部分HS,第二部分S,第三部分E,第四部分KD,第五部分JD
- exp_parameter = ["x", -10, 10, 1, 2] # 保护系统
- try:
- exp_parameter[0] = plot_parameter[0]
- exp_parameter[1] = int(plot_parameter[1])
- exp_parameter[2] = int(plot_parameter[2])
- exp_parameter[3] = int(plot_parameter[3])
- exp_parameter[4] = int(plot_parameter[4])
- except BaseException: # 迭代匹配直到出现错误
- pass
- plot_parameter = exp_parameter
- x_exp_scale = API.type_selection(
- ExpFunc(
- plot_parameter[0],
- "x",
- "",
- plot_parameter[1],
- plot_parameter[2],
- plot_parameter[3],
- plot_parameter[4],
- ).data_packet()[1]
- ) # 取y
- axis.set_xticks(x_exp_scale) # 输入表达式计算刻度
- elif x_scale.get()[0] == "y": # 输入函数y
- # 不错要错误捕捉,外围有个大的捕捉
- x_exp_scale = abs(int(start_x_plot.get()))
- x_major_locator = plt.MultipleLocator(x_exp_scale)
- axis.xaxis.set_major_locator(x_major_locator)
- else: # 输入纯数字
- x_exp_scale = API.type_selection(x_scale.get().split(","))
- axis.set_xticks(x_exp_scale)
- except BaseException:
- x_major_locator = plt.MultipleLocator(2)
- axis.xaxis.set_major_locator(x_major_locator)
- # 检测y
- try: # 意外捕捉
- if y_scale.get()[0] == "c": # 如果输入函数cx#-10#10#1#1
- plot_parameter = [
- y_scale.get()[1:],
- start_y_plot.get(),
- end_y_plot.get(),
- span_y_plot.get(),
- 2,
- ] # 第一部分HS,第二部分S,第三部分E,第四部分KD,第五部分JD
- exp_parameter = ["x", -10, 10, 1, 2] # 保护系统
- try:
- exp_parameter[0] = plot_parameter[0]
- exp_parameter[1] = int(plot_parameter[1])
- exp_parameter[2] = int(plot_parameter[2])
- exp_parameter[3] = int(plot_parameter[3])
- exp_parameter[4] = int(plot_parameter[4])
- except BaseException: # 迭代匹配直到出现错误
- pass
- plot_parameter = exp_parameter
- y_exp_scale = API.type_selection(
- ExpFunc(
- plot_parameter[0],
- "y",
- "",
- plot_parameter[1],
- plot_parameter[2],
- plot_parameter[3],
- plot_parameter[4],
- ).data_packet()[1]
- ) # 取y
- axis.set_yticks(y_exp_scale)
- elif y_scale.get()[0] == "y": # 输入函数y
- y_exp_scale = abs(int(start_y_plot.get()))
- y_major_locator = plt.MultipleLocator(y_exp_scale)
- axis.yaxis.set_major_locator(y_major_locator)
- else:
- y_exp_scale = API.type_selection(y_scale.get().split(","))
- axis.set_yticks(y_exp_scale)
- except BaseException:
- y_major_locator = plt.MultipleLocator(2)
- axis.yaxis.set_major_locator(y_major_locator)
- # 极限
- try:
- x_limit = API.type_selection(
- [start_x_limit.get(), end_x_limit.get()], type_=int, convert=False
- )
- y_limit = API.type_selection(
- [start_y_limit.get(), end_y_limit.get()], type_=int, convert=False
- )
- try:
- _x_limit = [x_limit[0], x_limit[1]]
- except BaseException:
- _x_limit = [-10, 10]
- try:
- _y_limit = [y_limit[0], y_limit[1]]
- except BaseException:
- _y_limit = _x_limit
- except BaseException:
- _x_limit = [-10, 10]
- _y_limit = [-10, 10]
- _x_limit.sort()
- _y_limit.sort()
- axis.set_xlim(_x_limit)
- axis.set_ylim(_y_limit)
- text_x = _x_limit[0] + abs(_x_limit[0]) * 0.01
- text_y = _y_limit[1] - abs(_y_limit[1]) * 0.01
- init()
- # 函数绘图系统
- API.output_prompt_gui("图像绘制中...")
- if func is None:
- return False
- if draw_type in (0, 1, 4, 5):
- # 绘制曲线
- get = func.get_plot_data()
- plot_x = get[0]
- plot_y = get[1]
- func_label = get[2]
- exp_style = get[3]
- first = True
- for i in range(len(plot_x)):
- plot_x = plot_x[i]
- plot_y = plot_y[i]
- if first:
- plt.plot(plot_x, plot_y, exp_style, label=func_label) # plot()画出曲线
- first = False
- else:
- plt.plot(plot_x, plot_y, exp_style)
- # 绘制记忆点
- get = func.get_memory()
- plot_memory_x = get[0]
- plot_memory_y = get[1]
- max_x, max_y, min_x, min_y = func.best_value()
- if show_point.get():
- plt.plot(
- plot_memory_x,
- plot_memory_y,
- exp_style[0] + "o",
- label=f"Point of {func_label}",
- ) # 画出一些点
- memory_x = sorted(list(set(plot_memory_x))) # 去除list重复项目
- extreme_points = max_x + min_x
- if show_text.get():
- last_x = None
- for i in range(len(memory_x)):
- if i in extreme_points:
- continue # 去除极值点
- now_x = memory_x[i] # x
- if last_x is None or abs(now_x - last_x) >= 1: # 确保位置
- num = plot_memory_x.index(now_x) # y的座位
- now_y = plot_memory_y[num]
- plt.text(
- now_x,
- now_y,
- f"({now_x},{int(now_y)})",
- fontdict={"size": "10", "color": "b"},
- ) # 标出坐标
- last_x = now_x
- if show_best_value.get():
- last_x = None
- plot_max = []
- for i in range(len(max_x)): # 画出最大值
- now_x = max_x[i]
- if last_x is None or abs(now_x - last_x) >= 1: # 确保位置
- if show_text.get():
- plt.text(
- now_x - 1,
- max_y,
- f"max:({now_x},{int(max_y)})",
- fontdict={"size": "10", "color": "b"},
- ) # 标出坐标
- plot_max.append(now_x)
- last_x = now_x
- last_x = None
- plot_min = []
- for i in range(len(min_x)): # 画出最小值
- now_x = min_x[i]
- if last_x is None or abs(now_x - last_x) >= 1:
- plot_min.append(now_x)
- if show_text.get():
- plt.text(
- now_x - 1,
- min_y,
- f"min:({now_x},{int(min_y)})",
- fontdict={"size": "10", "color": "b"},
- ) # 标出坐标
- last_x = now_x
- plt.plot(plot_min, [min_y] * len(plot_min), exp_style[0] + "o") # 画出一些点
- plt.plot(plot_max, [max_y] * len(plot_max), exp_style[0] + "o") # 画出一些点
- plt.legend() # 显示图示
- elif draw_type in (8, 9):
- get = func.data_packet()
- plot_x = get[0]
- plot_y = get[1]
- plot_x_len = len(plot_x)
- x_data = []
- y_data = []
- func_label = get[2]
- exp_style = get[3]
- plot_ln = axis.plot([], [], exp_style, label=func_label, animated=False)[0]
- text = plt.text(text_x, text_y, "", fontdict={"size": "10", "color": "b"})
- def _init():
- init()
- return plot_ln, text
- def update(n):
- nonlocal x_data, y_data
- if n == 0:
- x_data = []
- y_data = []
- x_data.append(plot_x[n])
- y_data.append(plot_y[n])
- text.set_text(f"x={plot_x[n]},y={plot_y[n]}")
- plot_ln.set_data(x_data, y_data)
- return plot_ln, text
- try: # 自定义帧率
- frame = int(frame_rate.get())
- except BaseException:
- frame = 100
- FuncAnimation(
- fig,
- update,
- frames=plot_x_len,
- init_func=_init,
- interval=frame,
- blit=False,
- repeat_delay=3000,
- ) # 动态绘图
- elif draw_type in (2, 3, 6, 7):
- text = plt.text(text_x, text_y, "", fontdict={"size": "10", "color": "b"})
- all_func = func.return_son()
- func_cul_list = []
- plot_x_len = len(all_func)
- m = [] # 每个群组中fx分类的个数
- for i in all_func: # 预先生成函数
- API.output_prompt_gui(f"迭代计算中...(共{plot_x_len}次)")
- get = i.get_plot_data()
- m.append(len(get[0]))
- func_cul_list.append(get)
- func_cul_list += func_cul_list[::-1]
- ln_list = [text]
- for i in range(max(m)):
- ln_list.append(
- axis.plot([], [], func_cul_list[0][3], animated=False)[0]
- ) # 创建足够的i
- plot_x_len = len(func_cul_list)
- def _init():
- init()
- text.set_text("")
- return None
- def update(n):
- get = func_cul_list[n - 1]
- ln_list[0].set_text(get[2])
- for i in range(max(m)):
- try:
- x = get[0][i]
- y = get[1][i]
- ln_list[i + 1].set_data(x, y)
- except BaseException:
- ln_list[i + 1].set_data([], [])
- return ln_list
- try: # 自定义帧率
- frame = int(frame_rate.get())
- except BaseException:
- frame = 100
- FuncAnimation(
- fig, update, frames=plot_x_len, init_func=_init, interval=frame, blit=False
- ) # 动态绘图
- API.output_prompt_gui("绘制完毕")
- plt.show() # 显示图像
- return True
- @staticmethod
- def set_function():
- global func
- default_value = API.set_func_gui()
- try:
- func = ExpFunc(*default_value, have_son=True)
- API.output_prompt_gui("应用成功")
- SCREEN.title(f"CoTan函数工厂 {func}")
- except BaseException:
- API.output_prompt_gui("应用失败2")
- raise
- def function_factory_main(): # H_S-默认函数GF-关闭时询问返回函数
- global SCREEN
- SCREEN.mainloop()
- SCREEN["bg"] = bg_color
- SCREEN.title("CoTan函数工厂")
- SCREEN.resizable(width=False, height=False)
- SCREEN.geometry("+10+10")
- FONT = (r"Font\ZKST.ttf", 11) # 设置字体
- rcParams["font.family"] = "simhei"
- rcParams["axes.unicode_minus"] = False
- tkinter.Label(
- SCREEN,
- text="输入解析式:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- func_exp = tkinter.Entry(SCREEN, width=gui_width * 2)
- func_exp.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="定义域前端点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- start_definition = tkinter.Entry(SCREEN, width=gui_width * 2)
- start_definition.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Label(
- SCREEN,
- text="定义域后端点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- end_definition = tkinter.Entry(SCREEN, width=gui_width * 2)
- end_definition.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Label(
- SCREEN,
- text="函数绘制跨度:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- span_definition = tkinter.Entry(SCREEN, width=gui_width * 2)
- span_definition.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Label(
- SCREEN,
- text="函数计算精度:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- accuracy = tkinter.Entry(SCREEN, width=gui_width * 2)
- accuracy.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="函数名字:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- func_name = tkinter.Entry(SCREEN, width=gui_width * 2)
- func_name.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="函数视图:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- func_style = tkinter.Entry(SCREEN, width=gui_width * 2)
- func_style.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="常量a默认值:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- default_a = tkinter.Entry(SCREEN, width=gui_width * 2)
- default_a.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="常量a起点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- start_a = tkinter.Entry(SCREEN, width=gui_width * 2)
- start_a.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="常量a终点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- end_a = tkinter.Entry(SCREEN, width=gui_width * 2)
- end_a.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="常量a跨度:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- span_a = tkinter.Entry(SCREEN, width=gui_width * 2)
- span_a.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="应用函数",
- command=API.set_function,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row, sticky=tkinter.E + tkinter.W
- ) # 添加函数
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="绘制图像",
- command=API.function_drawing,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="性质预测",
- command=API.property_prediction,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column + 2, row=row, sticky=tkinter.E + tkinter.W
- ) # 添加函数
- row += 1
- tkinter.Label(
- SCREEN,
- text="预测精度:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- prediction_accuracy = tkinter.Entry(SCREEN, width=gui_width * 2)
- prediction_accuracy.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- # 显示函数的xy
- prediction_box = tkinter.Listbox(SCREEN, width=gui_width * 3) # 暂时不启用多选
- prediction_box.grid(
- column=column,
- row=row,
- columnspan=3,
- rowspan=9,
- sticky=tkinter.S + tkinter.N + tkinter.E + tkinter.W,
- )
- column += 3
- tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
- column=column, row=0
- ) # 设置说明
- # 第二排的开始
- column += 1
- row = 0
- tkinter.Label(
- SCREEN,
- text="X轴刻度声明:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- x_scale = tkinter.Entry(SCREEN, width=gui_width * 2)
- x_scale.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="X轴刻度起点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- start_x_plot = tkinter.Entry(SCREEN, width=gui_width * 2)
- start_x_plot.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Label(
- SCREEN,
- text="X轴刻度终点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- start_x_polt = tkinter.Entry(SCREEN, width=gui_width * 2)
- start_x_polt.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Label(
- SCREEN,
- text="X轴刻度间隔:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- span_x_plot = tkinter.Entry(SCREEN, width=gui_width * 2)
- span_x_plot.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="Y轴刻度声明:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- y_scale = tkinter.Entry(SCREEN, width=gui_width * 2)
- y_scale.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="Y轴刻度起点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- start_y_plot = tkinter.Entry(SCREEN, width=gui_width * 2)
- start_y_plot.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Label(
- SCREEN,
- text="Y轴刻度终点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- end_y_plot = tkinter.Entry(SCREEN, width=gui_width * 2)
- end_y_plot.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="Y轴刻度间隔:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- span_y_plot = tkinter.Entry(SCREEN, width=gui_width * 2)
- span_y_plot.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="X轴显示起点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- start_x_limit = tkinter.Entry(SCREEN, width=gui_width * 2)
- start_x_limit.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Label(
- SCREEN,
- text="X轴显示终点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- end_x_limit = tkinter.Entry(SCREEN, width=gui_width * 2)
- end_x_limit.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="Y轴显示起点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- start_y_limit = tkinter.Entry(SCREEN, width=gui_width * 2)
- start_y_limit.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Label(
- SCREEN,
- text="Y轴显示终点:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- end_y_limit = tkinter.Entry(SCREEN, width=gui_width * 2)
- end_y_limit.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="帧率(帧/ms):",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- frame_rate = tkinter.Entry(SCREEN, width=gui_width * 2)
- frame_rate.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- show_point = tkinter.IntVar()
- show_best_value = tkinter.IntVar()
- show_text = tkinter.IntVar()
- tkinter.Checkbutton(
- SCREEN,
- bg=bg_color,
- fg=word_color,
- activebackground=bg_color,
- activeforeground=word_color,
- selectcolor=bg_color,
- text="显示记忆点",
- variable=show_point,
- ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
- tkinter.Checkbutton(
- SCREEN,
- bg=bg_color,
- fg=word_color,
- activebackground=bg_color,
- activeforeground=word_color,
- selectcolor=bg_color,
- text="显示最值",
- variable=show_best_value,
- ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
- tkinter.Checkbutton(
- SCREEN,
- bg=bg_color,
- fg=word_color,
- activebackground=bg_color,
- activeforeground=word_color,
- selectcolor=bg_color,
- text="显示文字",
- variable=show_text,
- ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
- row += 1
- # 显示函数的xy
- plot_type = tkinter.Listbox(
- SCREEN, width=gui_width * 3, height=gui_height * 4
- ) # 暂时不启用多选
- plot_type.grid(
- column=column,
- row=row,
- columnspan=3,
- rowspan=3,
- sticky=tkinter.S + tkinter.N + tkinter.E + tkinter.W,
- )
- plot_type.insert(
- tkinter.END,
- *[
- "笛卡尔坐标系静态图像(默认)",
- "矩形坐标系静态图像",
- "笛卡尔坐标系动态图像",
- "矩形坐标系动态图像",
- "笛卡尔坐标系静态图像(无线框)",
- "矩形坐标系静态图像(无线框)",
- "笛卡尔坐标系动态图像(无线框)",
- "矩形坐标系动态图像(无线框)",
- "笛卡尔坐标系动态画图",
- "矩形坐标系动态画图",
- ],
- )
- row += 3
- # 显示函数的xy
- prompt_box = tkinter.Listbox(
- SCREEN, width=gui_width * 3, height=gui_height * 2
- ) # 暂时不启用多选
- prompt_box.grid(
- column=column,
- row=row,
- columnspan=3,
- rowspan=2,
- sticky=tkinter.S + tkinter.N + tkinter.E + tkinter.W,
- )
- column += 3
- tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
- column=column, row=0
- ) # 设置说明
- column += 1
- row = 0
- tkinter.Label(
- SCREEN,
- text="计算(y):",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- x_value = tkinter.Entry(SCREEN, width=gui_width * 2)
- x_value.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(
- SCREEN,
- text="二分法计算(x):",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- y_value = tkinter.Entry(SCREEN, width=gui_width * 2)
- y_value.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- dicon_parameters = [] # 二分法参数输入
- name_list = [
- "最大迭代数",
- "计算精度",
- "最值允许偏移量",
- "零点最小间隔",
- "减少计算",
- "允许梯度计算",
- "最大扩张深度",
- "扩张限制",
- "扩张偏移量",
- "开启二级验证",
- "二级验证程度",
- ]
- for i in range(11):
- row += 1
- dicon_parameters.append(tkinter.StringVar())
- tkinter.Label(
- SCREEN,
- bg=bg_color,
- fg=word_color,
- text=name_list[i] + ":",
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- tkinter.Entry(SCREEN, width=gui_width * 2, textvariable=dicon_parameters[-1]).grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Label(
- SCREEN,
- text="梯度法计算(x):",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- y_value_gradient = tkinter.Entry(SCREEN, width=gui_width * 2)
- y_value_gradient.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- gradient_parameters = [] # 梯度法法参数输入
- name_list = ["梯度起点", "梯度终点", "计算深度", "计算精度"]
- for i in range(4):
- row += 1
- gradient_parameters.append(tkinter.StringVar())
- tkinter.Label(
- SCREEN,
- bg=bg_color,
- fg=word_color,
- text=name_list[i] + ":",
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- tkinter.Entry(
- SCREEN, width=gui_width * 2, textvariable=gradient_parameters[-1]
- ).grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
- row += 1
- tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, height=1).grid(
- column=1, row=row
- ) # 底部
- column += 3
- tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
- column=column, row=0
- ) # 设置说明
- column += 1
- row = 0
- tkinter.Label(
- SCREEN,
- text="代数法计算(x):",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- y_value_symbol = tkinter.Entry(SCREEN, width=gui_width * 2)
- y_value_symbol.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Label(
- SCREEN,
- text="求(x)导数:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- x_value_derivation = tkinter.Entry(SCREEN, width=gui_width * 2)
- x_value_derivation.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Label(
- SCREEN,
- text="逼近求导精度:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- proximity_accuracy = tkinter.Entry(SCREEN, width=gui_width * 2)
- proximity_accuracy.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="计算(y)",
- command=API.calculate,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row
- ) # 设置说明
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="二分法计算(x)",
- command=API.dichotomy,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(column=column + 1, row=row)
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="梯度法计算(x)",
- command=API.gradient_method_calculation,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(column=column + 2, row=row)
- row += 1
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="代数法计算",
- command=API.sympy_calculation_x,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(column=column, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="逼近法导数计算",
- command=API.approximation,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(column=column + 1, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="导数计算",
- command=API.function_differentiation,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(column=column + 2, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
- row += 1
- k = 5
- result_box = tkinter.Listbox(SCREEN, height=gui_height * (k - 1)) # 暂时不启用多选
- result_box.grid(
- column=column,
- row=row,
- columnspan=3,
- rowspan=k,
- sticky=tkinter.N + tkinter.E + tkinter.W,
- )
- row += k - 1
- tkinter.Label(
- SCREEN,
- text="性质预测值:",
- bg=bg_color,
- fg=word_color,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(
- column=column, row=row, sticky=tkinter.N + tkinter.S
- ) # 设置说明
- projection_value = tkinter.Entry(SCREEN, width=gui_width * 2)
- projection_value.grid(
- column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
- )
- row += 1
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="周期性",
- command=API.check_periodic,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(column=column, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="对称轴",
- command=API.check_symmetry_axis,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(column=column + 1, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="对称中心",
- command=API.check_center_of_symmetry,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(column=column + 2, row=row, sticky=tkinter.N + tkinter.E + tkinter.W)
- row += 1
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="单调性",
- command=API.check_monotonic,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(column=column, row=row, columnspan=3, sticky=tkinter.N + tkinter.E + tkinter.W)
- row += 1
- # 显示函数的xy
- projection_box = tkinter.Listbox(
- SCREEN, width=gui_width * 3, height=gui_height * 5
- ) # 暂时不启用多选
- projection_box.grid(
- column=column,
- row=row,
- columnspan=3,
- rowspan=6,
- sticky=tkinter.S + tkinter.N + tkinter.E + tkinter.W,
- )
- column += 3
- tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
- column=column, row=0
- ) # 设置说明
- column += 1
- row = 0
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="生成表格",
- command=API.save_to_sheet,
- font=FONT,
- width=gui_width * 2,
- height=gui_height,
- ).grid(column=column, row=row, columnspan=2)
- tkinter.Button(
- SCREEN,
- bg=botton_color,
- fg=word_color,
- text="导出表格",
- command=API.save_to_csv,
- font=FONT,
- width=gui_width,
- height=gui_height,
- ).grid(column=column + 2, row=row)
- row += 1
- # 显示函数的xy
- sheet_box = tkinter.Listbox(SCREEN, width=gui_width * 3) # 暂时不启用多选
- sheet_box.grid(
- column=column,
- row=row,
- columnspan=3,
- rowspan=17,
- sticky=tkinter.S + tkinter.N + tkinter.E + tkinter.W,
- )
- API.output_prompt_gui("加载完毕")
|