gui.py 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213
  1. import os
  2. import webbrowser
  3. import tkinter
  4. from newtkinter import askopenfilename, asksaveasfilename
  5. import tkinter.messagebox
  6. from tkinter.scrolledtext import ScrolledText
  7. import chardet
  8. import datascience.controller
  9. from system import exception_catch, QueueController
  10. queue_controller = QueueController()
  11. render_dict = {} # 保存了画图的List
  12. learn_dict = {} # 保存数据处理
  13. PATH = os.getcwd()
  14. sheet_list = []
  15. machine_controller = datascience.controller.MachineLearner()
  16. SCREEN = tkinter.Tk()
  17. bg_color = "#FFFAFA" # 主颜色
  18. buttom_bg_color = "#FFFAFA" # 按钮颜色
  19. word_color = "#000000" # 文字颜色
  20. SCREEN["bg"] = bg_color
  21. FONT = ("黑体", 11) # 设置字体
  22. FONT1 = ("黑体", 13)
  23. SCREEN.title("CoTan数据处理")
  24. SCREEN.resizable(width=False, height=False)
  25. SCREEN.geometry("+10+10") # 设置所在位置
  26. SCREEN.iconbitmap(bitmap=f'Pic{os.sep}favicon.ico', default=f'Pic{os.sep}favicon.ico')
  27. gui_width = 13 # 标准宽度
  28. gui_height = 2
  29. row = 0
  30. column = 0
  31. stored_list = []
  32. clean_list = []
  33. # 层叠多图
  34. base_image = None
  35. top_image = None
  36. # 数据清洗
  37. clean_default_script = """#输入你的数据清洗执行代码
  38. Done_Row=[] #输入操作的行号
  39. Done_Column=[] #输入操作的列号
  40. axis=True #True-操作行,False-操作列
  41. name='' #方法代号
  42. def check(data, row, column, get, R, C): #检查方法
  43. return True
  44. def done(data, row, column, get, R, C): #应用修正方法
  45. return DEL
  46. """
  47. clean_help = """
  48. 使用Python代码进行数据清洗
  49. 1)代码结构
  50. Done_Row=[] 代码用来检测的数据的列号
  51. Done_Column=[] 代码用来检测的数据的行号
  52. 不在以上指定范围内的数据将不会被检测,若为空则整个表格检测
  53. axis 执行删除方法时删除行或者列
  54. name 方法代号
  55. check 检查方法
  56. 输入:当前的值(输入的是一个值而不是一行(列)或整个列表)
  57. 输入:row和column当前值来自的行号(row)和列号(column)
  58. 输入:get当前检查的所有数据:类型是表格
  59. 输入:R和C当前值所来自的行和列的所有数据:类型是一维表格
  60. 输出:输出布尔为True代表该值可以使用,输出布尔为假表示该值不可使用
  61. done 不可使用的数值改造方法
  62. 输入:内容同上
  63. 输出:改造值或者DEL
  64. DEL:代表删除改值所在的行(axis=True)或列(axis=False)
  65. 2)扩展
  66. 默认:pd-pandas,re-re[正则表达式],Sheet-包含所有表格,用Sheet['name']访问名字为name的表格(注意引号别漏了)
  67. 支持:可以使用import导入语句,支持python语法
  68. """
  69. drawing_parameters = """
  70. 输入python变量赋值代码:渲染设置
  71. title #设置标题:str
  72. vice_title #设置副标题:str
  73. show_Legend #是否显示图例:bool
  74. show_Visual_mapping #是否使用视觉映射:bool
  75. is_color_Visual_mapping #是否为颜色视觉映射:bool[否则为大小视觉映射]
  76. min_Visual_mapping #映射的最小值
  77. max_Visual_mapping #映射的最大值
  78. ......(我太懒了, 设置太多不想写了)
  79. """
  80. class UIAPI:
  81. @staticmethod
  82. @exception_catch()
  83. def add_from_python_gui():
  84. file_dir = askopenfilename(
  85. title="选择载入的py", filetypes=[("Python", ".py"), ("Txt", ".txt")]
  86. )
  87. name = sheet_name.get().replace(" ", "")
  88. if name == "":
  89. name = os.path.splitext(os.path.split(file_dir)[1])[0]
  90. with open(file_dir, "r") as f:
  91. code = f.read()
  92. return code, name
  93. @staticmethod
  94. @exception_catch()
  95. def get_sheet_name_gui(): # 获得名字统一接口
  96. global sheet_list
  97. try:
  98. return sheet_list[sheet_box.curselection()[0]]
  99. except IndexError:
  100. try:
  101. return sheet_list[0]
  102. except IndexError:
  103. return None
  104. @staticmethod
  105. @exception_catch()
  106. def update_sheet_box_gui():
  107. global SCREEN, sheet_box, sheet_list
  108. sheet_list = machine_controller.get_sheet_list()
  109. sheet_box.delete(0, tkinter.END)
  110. sheet_box.insert(tkinter.END, *sheet_list)
  111. @staticmethod
  112. @exception_catch()
  113. def update_combo_box_gui():
  114. overlap_box.delete(0, tkinter.END)
  115. if base_image is not None:
  116. overlap_box.insert(tkinter.END, f"底图: {base_image}")
  117. if top_image is not None:
  118. overlap_box.insert(tkinter.END, f"顶图: {top_image}")
  119. @staticmethod
  120. @exception_catch()
  121. def add_csv_gui():
  122. file_dir = askopenfilename(title="选择载入的CSV", filetypes=[("CSV", ".csv")])
  123. csv_sep = sep.get()
  124. csv_encoding = encoding.get()
  125. str_ = bool(str_must.get())
  126. index = bool(index_must.get())
  127. name = sheet_name.get().replace(" ", "")
  128. if name == "":
  129. name = os.path.splitext(os.path.split(file_dir)[1])[0]
  130. if csv_encoding == "":
  131. with open(file_dir, "rb") as f:
  132. csv_encoding = chardet.detect(f.read())["encoding"]
  133. if csv_sep == "":
  134. csv_sep = ","
  135. return csv_encoding, csv_sep, file_dir, index, name, str_
  136. @staticmethod
  137. @exception_catch()
  138. def to_csv_gui():
  139. save_dir = asksaveasfilename(title="选择保存的CSV", filetypes=[("CSV", ".csv")])
  140. csv_sep = sep.get()
  141. return csv_sep, save_dir
  142. @staticmethod
  143. @exception_catch()
  144. def update_index_box_gui(index):
  145. global SCREEN, index_box
  146. index_box.delete(0, tkinter.END)
  147. index_box.insert(tkinter.END, *index)
  148. @staticmethod
  149. @exception_catch()
  150. def vitables_gui(data, name):
  151. global bg_color, FONT1
  152. new_top = tkinter.Toplevel(bg=bg_color)
  153. new_top.title(name)
  154. new_top.geometry("+10+10") # 设置所在位置
  155. text = ScrolledText(new_top, font=FONT1, height=50)
  156. text.pack(fill=tkinter.BOTH)
  157. text.insert("0.0", data)
  158. text.config(state=tkinter.DISABLED)
  159. new_top.resizable(width=False, height=False)
  160. @staticmethod
  161. @exception_catch()
  162. def get_des_bool_gui():
  163. return bool(des_bool.get())
  164. @staticmethod
  165. @exception_catch()
  166. def sort_by_column_gui():
  167. ascending = not bool(ascending_type.get())
  168. new = bool(ascending_new.get())
  169. return new, ascending
  170. @staticmethod
  171. @exception_catch()
  172. def add_baseline_gui(ascending_type_, sort_by_):
  173. ascending = not bool(ascending_type_.get())
  174. value = int(sort_by_.get())
  175. return ascending, value
  176. @staticmethod
  177. @exception_catch()
  178. def update_sort_box_gui():
  179. global stored_list, stored_box
  180. re = []
  181. d = {True: "正序", False: "倒叙"}
  182. for i in stored_list:
  183. re.append(f"列号:{i[0]}, 排序方式{d[i[1]]}")
  184. stored_box.delete(0, tkinter.END)
  185. stored_box.insert(tkinter.END, *re)
  186. @staticmethod
  187. @exception_catch()
  188. def get_stored_box_index_gui():
  189. return stored_box.curselection()[0]
  190. @staticmethod
  191. @exception_catch()
  192. def get_ascending_new_gui():
  193. new = bool(ascending_new.get())
  194. return new
  195. @staticmethod
  196. @exception_catch()
  197. def slice_data_gui():
  198. def split_slice_core(slice_list, func_type):
  199. a = []
  200. for i in slice_list:
  201. b = i.get().replace(" ", "")
  202. if b == "":
  203. a.append(None)
  204. else:
  205. try:
  206. a.append(func_type(b))
  207. except ValueError:
  208. a.append(None)
  209. if a[0] is not None and a[1] is None:
  210. a[1] = a[0] + 1
  211. a[2] = None
  212. return a
  213. the_column_type = column_type.get()
  214. is_iloc = True
  215. if the_column_type == 0: # 输入的列号
  216. column_ = slice(*split_slice_core(column_clist, int))
  217. elif the_column_type == 1:
  218. is_iloc = False
  219. column_ = slice(*split_slice_core(column_clist, str))
  220. else:
  221. get = column_clist[0].get().replace(" ", "").split(",")
  222. column_ = []
  223. for i in get:
  224. try:
  225. column_.append(int(i))
  226. except ValueError:
  227. pass
  228. the_row_type = row_type.get()
  229. if the_row_type == 0: # 输入的列号
  230. row_ = slice(*split_slice_core(row_clist, int))
  231. elif the_row_type == 1:
  232. row_ = slice(*split_slice_core(row_clist, str))
  233. else:
  234. get = row_clist[0].get().replace(" ", "").split(",")
  235. row_ = []
  236. for i in get:
  237. try:
  238. row_.append(int(i))
  239. except ValueError:
  240. pass
  241. new = bool(slice_new.get())
  242. return column_, is_iloc, new, row_
  243. @staticmethod
  244. @exception_catch()
  245. def del_data_gui():
  246. column_ = column_clist[0].get().replace(" ", "").split(",")
  247. row_ = row_clist[0].get().replace(" ", "").split(",")
  248. new = bool(slice_new.get())
  249. return column_, new, row_
  250. @staticmethod
  251. @exception_catch()
  252. def get_clean_code_gui():
  253. exp = clean_code.get("0.0", tkinter.END)
  254. return exp
  255. @staticmethod
  256. @exception_catch()
  257. def get_clean_func_box_index_gui():
  258. return clean_func_box.curselection()[0]
  259. @staticmethod
  260. @exception_catch()
  261. def show_dictionary_gui():
  262. tkinter.messagebox.showinfo("帮助字典", clean_help)
  263. @staticmethod
  264. @exception_catch()
  265. def open_python_for_clean_gui():
  266. global clean_code
  267. file_dir = askopenfilename(
  268. title="打开Python脚本", filetypes=[("Python", ".py"), ("TXT", ".txt")]
  269. )
  270. with open(file_dir) as f:
  271. get = f.read()
  272. clean_code.delete("0.0", tkinter.END)
  273. clean_code.insert("0.0", get)
  274. @staticmethod
  275. @exception_catch()
  276. def reset_clean_code_gui():
  277. global clean_code, clean_default_script
  278. API.update_clean_code_gui(clean_default_script)
  279. @staticmethod
  280. @exception_catch()
  281. def update_render_box_gui():
  282. global render_dict, render_box, machine_controller
  283. render_dict = machine_controller.get_all_render()
  284. render_box.delete(0, tkinter.END)
  285. render_box.insert(tkinter.END, *render_dict.keys())
  286. @staticmethod
  287. @exception_catch()
  288. def get_draw_as_well_gui():
  289. return bool(draw_as_well.get())
  290. @staticmethod
  291. @exception_catch()
  292. def render_box_index_gui():
  293. return render_box.curselection()[0]
  294. @staticmethod
  295. @exception_catch()
  296. def rendering_one_gui():
  297. render_dir = asksaveasfilename(title="选择渲染保存地址", filetypes=[("HTML", ".html")])
  298. try:
  299. assert render_dir.startswith(".html")
  300. except AssertionError:
  301. render_dir += ".html"
  302. return render_dir
  303. @staticmethod
  304. @exception_catch()
  305. def rendering_gui():
  306. render_dir = asksaveasfilename(title="选择渲染保存地址", filetypes=[("HTML", ".html")])
  307. try:
  308. assert render_dir.startswith(".html")
  309. except AssertionError:
  310. render_dir += ".html"
  311. return render_dir
  312. @staticmethod
  313. @exception_catch()
  314. def set_dtype_gui():
  315. type_ = bool(dtype_func.get())
  316. name = API.get_sheet_name_gui()
  317. column_list = dtype_column.get().split(",")
  318. if column_list == [""]:
  319. column_list = []
  320. dtype = dtype_input.get()
  321. wrong = dtype_wrong.get()
  322. return column_list, dtype, name, type_, wrong
  323. @staticmethod
  324. @exception_catch()
  325. def update_clean_code_gui(clean_default_script_):
  326. clean_code.delete("0.0", tkinter.END)
  327. clean_code.insert("0.0", clean_default_script_)
  328. @staticmethod
  329. @exception_catch()
  330. def datetime_index_gui():
  331. is_column = bool(replace_index.get()) # 操作行名-False,操作列名-True
  332. save = bool(replace_type[0].get())
  333. k = ["start", "end", "freq"]
  334. init = {}
  335. for i in range(len(date_input)):
  336. data = date_input[i].get()
  337. if data == "":
  338. continue
  339. init[k[i]] = data
  340. if len(init) == 3:
  341. if bool(date_type.get()): # 使用间隔
  342. del init["end"]
  343. else:
  344. del init["freq"]
  345. return init, is_column, save
  346. @staticmethod
  347. @exception_catch()
  348. def num_with_name_gui():
  349. is_column = bool(replace_index.get()) # 操作行名-False,操作列名-True
  350. save = bool(replace_type[0].get())
  351. return is_column, save
  352. @staticmethod
  353. @exception_catch()
  354. def num_to_name_gui():
  355. is_column = bool(replace_index.get()) # 操作行名-False,操作列名-True
  356. save = bool(replace_type[0].get())
  357. return is_column, save
  358. @staticmethod
  359. @exception_catch()
  360. def change_index_gui():
  361. is_column = bool(replace_index.get()) # 操作行名-False,操作列名-True
  362. iloc = int(replace_iloc.get()) # 替换的列号(行号)
  363. save = bool(replace_type[0].get())
  364. drop = not bool(replace_type[1].get())
  365. return drop, iloc, is_column, save
  366. @staticmethod
  367. @exception_catch()
  368. def replace_index_func_gui():
  369. the_replace_dict = eval(replace_dict.get())
  370. is_column = bool(replace_index.get()) # 操作行-False,操作列-True
  371. save = bool(replace_type[0].get())
  372. return is_column, save, the_replace_dict
  373. @staticmethod
  374. @exception_catch()
  375. def update_leaner_box_gui():
  376. global learn_dict, learner_box
  377. learn_dict = machine_controller.return_learner()
  378. learner_box.delete(0, tkinter.END)
  379. learner_box.insert(tkinter.END, *learn_dict.keys())
  380. @staticmethod
  381. @exception_catch()
  382. def get_data_split_gui():
  383. try:
  384. split = float(data_split.get())
  385. assert not split < 0 or 1 < split
  386. except (AssertionError, ValueError):
  387. split = 0.3
  388. return split
  389. @staticmethod
  390. @exception_catch()
  391. def set_learner_gui():
  392. global chose_learner
  393. chose_learner.set(API.get_learner_name_gui(True))
  394. @staticmethod
  395. @exception_catch()
  396. def get_learner_name_gui(learner_type=False):
  397. global learn_dict, learner_box, chose_learner
  398. if learner_type:
  399. try:
  400. return list(learn_dict.keys())[learner_box.curselection()[0]]
  401. except IndexError:
  402. try:
  403. return list(learn_dict.keys)[0]
  404. except IndexError:
  405. return None
  406. else:
  407. return chose_learner.get()
  408. @staticmethod
  409. @exception_catch()
  410. def askokcancel_gui(messgae):
  411. return tkinter.messagebox.askokcancel("提示", messgae)
  412. @staticmethod
  413. @exception_catch()
  414. def show_tips_gui():
  415. tkinter.messagebox.showinfo("使用提示", drawing_parameters)
  416. @staticmethod
  417. @exception_catch()
  418. def show_sorry_gui():
  419. tkinter.messagebox.showinfo("非常抱歉", "高级别的机器学习请到机器学习板块深入研究...")
  420. class API(UIAPI):
  421. @staticmethod
  422. @exception_catch()
  423. def view_cleaning_script():
  424. name = clean_list[API.get_clean_func_box_index_gui()]
  425. API.update_clean_code_gui(machine_controller.get_clean_code(name))
  426. @staticmethod
  427. @exception_catch()
  428. def clear_rendering():
  429. machine_controller.clean_render()
  430. API.update_render_box_gui()
  431. @staticmethod
  432. @exception_catch()
  433. def del_form():
  434. name = API.get_sheet_name_gui()
  435. machine_controller.del_sheet(name)
  436. API.update_sheet_box_gui()
  437. @staticmethod
  438. @exception_catch()
  439. def del_learner():
  440. learner = API.get_learner_name_gui(True)
  441. set_learne = API.get_learner_name_gui(False) # 获取学习器Learner
  442. if set_learne != learner:
  443. machine_controller.del_leaner(learner)
  444. API.update_leaner_box_gui()
  445. @staticmethod
  446. @exception_catch()
  447. def visual_learner():
  448. learner = API.get_learner_name_gui(True)
  449. data = machine_controller.visual_learner(
  450. learner, API.askokcancel_gui(f"是否将数据生成表格。\n(可绘制成散点图对比数据)")
  451. )
  452. API.vitables_gui(
  453. f"对象:{learner}\n\n{data[0]}\n\n\n{data[1]}", f"CoTan数据处理 查看数据:{learner}"
  454. )
  455. API.update_sheet_box_gui()
  456. @staticmethod
  457. @exception_catch()
  458. def get_learner_config():
  459. return learner_parameters.get("0.0", tkinter.END)
  460. @staticmethod
  461. @exception_catch()
  462. def test_learner():
  463. name = API.get_sheet_name_gui() # 表格数据
  464. learner = API.get_learner_name_gui()
  465. try:
  466. split = float(data_split.get())
  467. assert not split < 0 or 1 < split
  468. except (AssertionError, ValueError):
  469. split = 0.3
  470. socore = machine_controller.training_machine(
  471. name, learner, Score_Only=True, split=split
  472. )[1]
  473. tkinter.messagebox.showinfo("测试完成", f"针对测试数据评分结果为:{socore}")
  474. @staticmethod
  475. @exception_catch()
  476. def predict_learner():
  477. name = API.get_sheet_name_gui() # 表格数据
  478. learner = API.get_learner_name_gui()
  479. data = machine_controller.predict(name, learner)
  480. title = f"CoTan数据处理 表格:{name} 学习器:{learner}"
  481. API.vitables_gui(data, title)
  482. API.update_sheet_box_gui()
  483. @staticmethod
  484. @exception_catch()
  485. def fit_learner():
  486. name = API.get_sheet_name_gui() # 表格数据
  487. learner = API.get_learner_name_gui()
  488. split = API.get_data_split_gui()
  489. socore = machine_controller.training_machine(
  490. name, learner, parameters=API.get_learner_config(), split=split
  491. )
  492. tkinter.messagebox.showinfo(
  493. "训练完成",
  494. f"针对训练数据({(1 - split) * 100}%)评分结果为:{socore[0]}\n"
  495. f"针对测试数据评分({split * 100}%)结果为:{socore[1]}",
  496. )
  497. @staticmethod
  498. @exception_catch()
  499. def add_knn_class():
  500. API.add_learner_core("Knn_class")
  501. @staticmethod
  502. @exception_catch()
  503. def add_logistic_regression():
  504. API.add_learner_core("LogisticRegression")
  505. @staticmethod
  506. @exception_catch()
  507. def add_lasso():
  508. API.add_learner_core("Lasso")
  509. @staticmethod
  510. @exception_catch()
  511. def add_knn_regression():
  512. API.add_learner_core("Knn")
  513. @staticmethod
  514. @exception_catch()
  515. def add_ridge():
  516. API.add_learner_core("Ridge")
  517. @staticmethod
  518. @exception_catch()
  519. def add_generalized_linear():
  520. API.add_learner_core("Line")
  521. @staticmethod
  522. @exception_catch()
  523. def add_learner_core(learner_type): # 添加Lenear的核心
  524. machine_controller.add_learner(learner_type, parameters=API.get_learner_config())
  525. API.update_leaner_box_gui()
  526. @staticmethod
  527. @exception_catch()
  528. def feature_extraction():
  529. name = API.get_sheet_name_gui()
  530. machine_controller.decision_tree_classifier(name)
  531. API.update_sheet_box_gui()
  532. @staticmethod
  533. @exception_catch()
  534. def replace_index_func():
  535. name = API.get_sheet_name_gui()
  536. is_column, save, the_replace_dict = API.replace_index_func_gui()
  537. machine_controller.replace_index(name, is_column, the_replace_dict, save)
  538. API.update_sheet_box_gui()
  539. @staticmethod
  540. @exception_catch()
  541. def change_index():
  542. name = API.get_sheet_name_gui() # 名字
  543. drop, iloc, is_column, save = API.change_index_gui()
  544. machine_controller.change_index(name, is_column, iloc, save, drop)
  545. API.update_sheet_box_gui()
  546. @staticmethod
  547. @exception_catch()
  548. def num_to_name():
  549. name = API.get_sheet_name_gui() # 名字
  550. is_column, save = API.num_to_name_gui()
  551. machine_controller.number_naming(name, is_column, save)
  552. API.update_sheet_box_gui()
  553. @staticmethod
  554. @exception_catch()
  555. def num_with_name():
  556. name = API.get_sheet_name_gui() # 名字
  557. is_column, save = API.num_with_name_gui()
  558. machine_controller.name_with_number(name, is_column, save)
  559. API.update_sheet_box_gui()
  560. @staticmethod
  561. @exception_catch()
  562. def datetime_index(is_date=True):
  563. name = API.get_sheet_name_gui() # 名字
  564. init, is_column, save = API.datetime_index_gui()
  565. if is_date:
  566. machine_controller.date_index(name, is_column, save, **init)
  567. else:
  568. machine_controller.time_naming(name, is_column, save, **init)
  569. API.update_sheet_box_gui()
  570. @staticmethod
  571. @exception_catch()
  572. def date_index():
  573. API.datetime_index(True)
  574. @staticmethod
  575. @exception_catch()
  576. def time_index():
  577. API.datetime_index(False)
  578. @staticmethod
  579. @exception_catch()
  580. def set_dtype():
  581. column_list, dtype, name, type_, wrong = API.set_dtype_gui()
  582. if type_: # 软转换
  583. if wrong != "ignore":
  584. wrong = "coerce"
  585. machine_controller.set_dtype(name, column_list, dtype, wrong)
  586. else:
  587. machine_controller.as_dtype(name, column_list, dtype, "ignore")
  588. API.update_sheet_box_gui()
  589. @staticmethod
  590. @exception_catch()
  591. def python_render(): # 导入绘制方法
  592. file_dir = askopenfilename(
  593. title="打开Python脚本", filetypes=[("Python", ".py"), ("TXT", ".txt")]
  594. )
  595. with open(file_dir) as f:
  596. code = f.read()
  597. API.new_render(machine_controller.custom_graph(code), "自定义图")
  598. @staticmethod
  599. @exception_catch()
  600. def get_rendering_parameters(): # 获取画图的args
  601. return rendering_parameters.get("0.0", tkinter.END)
  602. @staticmethod
  603. @exception_catch()
  604. def rendering():
  605. render_dir = API.rendering_gui()
  606. webbrowser.open(
  607. machine_controller.render_all(API.get_rendering_parameters(), render_dir)
  608. )
  609. API.update_render_box_gui()
  610. @staticmethod
  611. @exception_catch()
  612. def rendering_one():
  613. render_dir = API.rendering_one_gui()
  614. list(render_dict.values())[API.render_box_index_gui()].render(render_dir)
  615. webbrowser.open(render_dir)
  616. API.update_render_box_gui()
  617. @staticmethod
  618. @exception_catch()
  619. def make_overlap():
  620. global top_image, base_image
  621. if base_image is not None and top_image is not None:
  622. try:
  623. API.new_render(machine_controller.overlap(base_image, top_image), f"合成图")
  624. except BaseException:
  625. raise
  626. base_image = None
  627. top_image = None
  628. API.update_combo_box_gui()
  629. @staticmethod
  630. @exception_catch()
  631. def add_basemap():
  632. global base_image
  633. base_image = list(render_dict.keys())[API.render_box_index_gui()]
  634. API.update_combo_box_gui()
  635. @staticmethod
  636. @exception_catch()
  637. def add_top_image():
  638. global top_image
  639. top_image = list(render_dict.keys())[API.render_box_index_gui()]
  640. API.update_combo_box_gui()
  641. @staticmethod
  642. @exception_catch()
  643. def del_rendering():
  644. key = list(render_dict.keys())[API.render_box_index_gui()]
  645. machine_controller.del_render(key)
  646. API.update_render_box_gui()
  647. @staticmethod
  648. @exception_catch()
  649. def new_render(c, name):
  650. if API.get_draw_as_well_gui():
  651. c.render(fr"{PATH}{os.sep}{name}.html")
  652. API.update_render_box_gui()
  653. @staticmethod
  654. @exception_catch()
  655. def to_geo():
  656. name = API.get_sheet_name_gui()
  657. API.new_render(machine_controller.to_geo(name, API.get_rendering_parameters()), "Geo地图")
  658. @staticmethod
  659. @exception_catch()
  660. def to_map():
  661. name = API.get_sheet_name_gui()
  662. API.new_render(machine_controller.to_map(name, API.get_rendering_parameters()), "Map地图")
  663. @staticmethod
  664. @exception_catch()
  665. def to_scattergeo():
  666. name = API.get_sheet_name_gui()
  667. API.new_render(
  668. machine_controller.to_scattergeo(name, API.get_rendering_parameters()), "Geo点地图"
  669. )
  670. @staticmethod
  671. @exception_catch()
  672. def to_treemap():
  673. name = API.get_sheet_name_gui()
  674. API.new_render(machine_controller.to_tree_map(name, API.get_rendering_parameters()), "矩形树图")
  675. @staticmethod
  676. @exception_catch()
  677. def to_tree():
  678. name = API.get_sheet_name_gui()
  679. API.new_render(machine_controller.to_tree(name, API.get_rendering_parameters()), "树状图")
  680. @staticmethod
  681. @exception_catch()
  682. def to_sankey():
  683. name = API.get_sheet_name_gui()
  684. API.new_render(machine_controller.to_sankey(name, API.get_rendering_parameters()), "桑基图")
  685. @staticmethod
  686. @exception_catch()
  687. def to_sunburst():
  688. name = API.get_sheet_name_gui()
  689. API.new_render(machine_controller.to_sunburst(name, API.get_rendering_parameters()), "旭日图")
  690. @staticmethod
  691. @exception_catch()
  692. def to_theme_river():
  693. name = API.get_sheet_name_gui()
  694. API.new_render(
  695. machine_controller.to_theme_river(name, API.get_rendering_parameters()), "河流图"
  696. )
  697. @staticmethod
  698. @exception_catch()
  699. def to_calendar():
  700. name = API.get_sheet_name_gui()
  701. API.new_render(machine_controller.to_calendar(name, API.get_rendering_parameters()), "日历图")
  702. @staticmethod
  703. @exception_catch()
  704. def to_gauge():
  705. name = API.get_sheet_name_gui()
  706. API.new_render(machine_controller.to_gauge(name, API.get_rendering_parameters()), "仪表图")
  707. @staticmethod
  708. @exception_catch()
  709. def to_liquid():
  710. name = API.get_sheet_name_gui()
  711. API.new_render(machine_controller.to_liquid(name, API.get_rendering_parameters()), "水球图")
  712. @staticmethod
  713. @exception_catch()
  714. def to_line3d():
  715. name = API.get_sheet_name_gui()
  716. API.new_render(machine_controller.to_line3d(name, API.get_rendering_parameters()), "3D折线图")
  717. @staticmethod
  718. @exception_catch()
  719. def to_scatter3d():
  720. name = API.get_sheet_name_gui()
  721. API.new_render(
  722. machine_controller.to_scatter3d(name, API.get_rendering_parameters()), "3D散点图"
  723. )
  724. @staticmethod
  725. @exception_catch()
  726. def to_bar3d():
  727. name = API.get_sheet_name_gui()
  728. API.new_render(machine_controller.to_bar3d(name, API.get_rendering_parameters()), "3D柱状图")
  729. @staticmethod
  730. @exception_catch()
  731. def to_word_cloud():
  732. name = API.get_sheet_name_gui()
  733. API.new_render(
  734. machine_controller.to_word_cloud(name, API.get_rendering_parameters()), "词云图"
  735. )
  736. @staticmethod
  737. @exception_catch()
  738. def to_radar():
  739. name = API.get_sheet_name_gui()
  740. API.new_render(machine_controller.to_radar(name, API.get_rendering_parameters()), "雷达图")
  741. @staticmethod
  742. @exception_catch()
  743. def to_polar():
  744. name = API.get_sheet_name_gui()
  745. API.new_render(machine_controller.to_polar(name, API.get_rendering_parameters()), "极坐标图")
  746. @staticmethod
  747. @exception_catch()
  748. def to_pie():
  749. name = API.get_sheet_name_gui()
  750. API.new_render(machine_controller.to_pie(name, API.get_rendering_parameters()), "饼图")
  751. @staticmethod
  752. @exception_catch()
  753. def to_parallel():
  754. name = API.get_sheet_name_gui()
  755. API.new_render(machine_controller.to_parallel(name, API.get_rendering_parameters()), "多轴图")
  756. @staticmethod
  757. @exception_catch()
  758. def to_graph():
  759. name = API.get_sheet_name_gui()
  760. API.new_render(machine_controller.to_graph(name, API.get_rendering_parameters()), "关系图")
  761. @staticmethod
  762. @exception_catch()
  763. def to_format_graph():
  764. name = API.get_sheet_name_gui()
  765. API.new_render(
  766. machine_controller.to_format_graph(name, API.get_rendering_parameters()), "关系图"
  767. )
  768. @staticmethod
  769. @exception_catch()
  770. def to_funnel():
  771. name = API.get_sheet_name_gui()
  772. API.new_render(machine_controller.to_funnel(name, API.get_rendering_parameters()), "漏斗图")
  773. @staticmethod
  774. @exception_catch()
  775. def to_heat_map():
  776. name = API.get_sheet_name_gui()
  777. API.new_render(machine_controller.to_heatmap(name, API.get_rendering_parameters()), "热力图")
  778. @staticmethod
  779. @exception_catch()
  780. def to_boxpolt():
  781. name = API.get_sheet_name_gui()
  782. API.new_render(machine_controller.to_boxpolt(name, API.get_rendering_parameters()), "箱形图")
  783. @staticmethod
  784. @exception_catch()
  785. def to_pictorialbar():
  786. name = API.get_sheet_name_gui()
  787. API.new_render(
  788. machine_controller.to_pictorialbar(name, API.get_rendering_parameters()), "象形柱状图"
  789. )
  790. @staticmethod
  791. @exception_catch()
  792. def to_scatter():
  793. name = API.get_sheet_name_gui()
  794. API.new_render(machine_controller.to_scatter(name, API.get_rendering_parameters()), "散点图")
  795. @staticmethod
  796. @exception_catch()
  797. def to_line():
  798. name = API.get_sheet_name_gui()
  799. API.new_render(machine_controller.to_line(name, API.get_rendering_parameters()), "折线图")
  800. @staticmethod
  801. @exception_catch()
  802. def to_bar():
  803. name = API.get_sheet_name_gui()
  804. API.new_render(machine_controller.to_bar(name, API.get_rendering_parameters()), "柱状图")
  805. @staticmethod
  806. @exception_catch()
  807. def empty_cleaning_script():
  808. machine_controller.del_all_clean_func()
  809. API.update_cleaning_script_box()
  810. @staticmethod
  811. @exception_catch()
  812. def execute_cleaning_script():
  813. name = API.get_sheet_name_gui()
  814. data = machine_controller.data_clean(name)
  815. title = f"CoTan数据处理 表格:{name}.数据清洗"
  816. API.vitables_gui(data, title)
  817. API.update_sheet_box_gui()
  818. @staticmethod
  819. @exception_catch()
  820. def del_cleaning_script():
  821. name = clean_list[API.get_clean_func_box_index_gui()]
  822. machine_controller.del_clean_func(name)
  823. API.update_cleaning_script_box()
  824. @staticmethod
  825. @exception_catch()
  826. def update_cleaning_script_box():
  827. global clean_list
  828. clean_list = machine_controller.get_clean_func()
  829. clean_func_box.delete(0, tkinter.END)
  830. clean_func_box.insert(tkinter.END, *clean_list)
  831. @staticmethod
  832. @exception_catch()
  833. def add_cleaning_script():
  834. exp = API.get_clean_code_gui()
  835. machine_controller.add_clean_func(exp)
  836. API.update_cleaning_script_box()
  837. @staticmethod
  838. @exception_catch()
  839. def clean_cleaning_script():
  840. exp = API.get_clean_code_gui()
  841. machine_controller.add_clean_func(exp)
  842. API.update_cleaning_script_box()
  843. @staticmethod
  844. @exception_catch()
  845. def clean_nan_row():
  846. name = API.get_sheet_name_gui()
  847. data = machine_controller.del_nan(name, True)
  848. title = f"CoTan数据处理 表格:{name}.NaN"
  849. API.vitables_gui(data, title)
  850. API.update_sheet_box_gui()
  851. @staticmethod
  852. @exception_catch()
  853. def is_nan():
  854. name = API.get_sheet_name_gui()
  855. data = machine_controller.is_nan(name)
  856. title = f"CoTan数据处理 表格:{name}.NaN"
  857. API.vitables_gui(data, title)
  858. API.update_sheet_box_gui()
  859. @staticmethod
  860. @exception_catch()
  861. def to_bool():
  862. the_bool_exp = bool_exp.get()
  863. name = API.get_sheet_name_gui()
  864. data = machine_controller.to_bool(name, the_bool_exp, True)
  865. title = f"CoTan数据处理 表格:{name} 布尔化"
  866. API.vitables_gui(data, title)
  867. API.update_sheet_box_gui()
  868. @staticmethod
  869. @exception_catch()
  870. def del_data():
  871. name = API.get_sheet_name_gui()
  872. column_, new, row_ = API.del_data_gui()
  873. data = "None 你的操作不被允许"
  874. try:
  875. data = machine_controller.del_slice(name, column_, row_, new)
  876. except BaseException:
  877. raise
  878. finally:
  879. title = f"CoTan数据处理 表格:{name}"
  880. API.vitables_gui(data, title)
  881. API.update_sheet_box_gui()
  882. @staticmethod
  883. @exception_catch()
  884. def slice_data():
  885. column_, is_iloc, new, row_ = API.slice_data_gui()
  886. name = API.get_sheet_name_gui()
  887. data = "None 你的操作不被允许"
  888. try:
  889. data = machine_controller.get_slice(name, column_, row_, is_iloc, new)
  890. except BaseException:
  891. raise
  892. finally:
  893. title = f"CoTan数据处理 表格:{name}"
  894. API.vitables_gui(data, title)
  895. API.update_sheet_box_gui()
  896. @staticmethod
  897. @exception_catch()
  898. def sample_data():
  899. name = API.get_sheet_name_gui()
  900. new = API.get_ascending_new_gui()
  901. data = machine_controller.sample(name, new)
  902. title = f"CoTan数据处理 打乱表格:{name}"
  903. API.vitables_gui(data, title)
  904. API.update_sheet_box_gui()
  905. @staticmethod
  906. @exception_catch()
  907. def stored_value():
  908. name = API.get_sheet_name_gui()
  909. new = API.get_ascending_new_gui()
  910. data = machine_controller.stored_value(name, stored_list, new)
  911. title = f"CoTan数据处理 表格:{name}.Stored"
  912. API.vitables_gui(data, title)
  913. API.update_sheet_box_gui()
  914. @staticmethod
  915. @exception_catch()
  916. def del_baseline():
  917. global stored_list, stored_box
  918. del stored_list[API.get_stored_box_index_gui()]
  919. API.update_sort_box_gui()
  920. @staticmethod
  921. @exception_catch()
  922. def add_baseline(): # 按基准列排行
  923. ascending, value = API.add_baseline_gui(ascending_type, sort_by)
  924. stored_list.append((value, ascending))
  925. API.update_sort_box_gui()
  926. @staticmethod
  927. @exception_catch()
  928. def sort_by_column(): # 行
  929. name = API.get_sheet_name_gui()
  930. new, ascending = API.sort_by_column_gui()
  931. data = machine_controller.sorted_index(name, False, new, ascending)
  932. title = f"CoTan数据处理 表格:{name}.Stored by Column"
  933. API.vitables_gui(data, title)
  934. API.update_sheet_box_gui()
  935. @staticmethod
  936. @exception_catch()
  937. def sort_by_tow(): # 行
  938. name = API.get_sheet_name_gui()
  939. new, ascending = API.sort_by_column_gui()
  940. data = machine_controller.sorted_index(name, True, new, ascending)
  941. title = f"CoTan数据处理 表格:{name}.Stored by Row"
  942. API.vitables_gui(data, title)
  943. API.update_sheet_box_gui()
  944. @staticmethod
  945. @exception_catch()
  946. def transpose():
  947. name = API.get_sheet_name_gui()
  948. new = API.get_ascending_new_gui()
  949. data = machine_controller.transpose(name, new)
  950. title = f"CoTan数据处理 表格:{name}.T"
  951. API.vitables_gui(data, title)
  952. API.update_sheet_box_gui()
  953. @staticmethod
  954. @exception_catch()
  955. def show_report():
  956. assert not API.askokcancel_gui(f"是否统计数据,大量的数据需要耗费一定的时间(确定后,系统会在后台统计)")
  957. report_dir = f"{PATH}{os.sep}$Show_Des_Sheet.html"
  958. name = API.get_sheet_name_gui()
  959. assert not name is None
  960. machine_controller.to_report(name, report_dir)
  961. webbrowser.open(report_dir)
  962. @staticmethod
  963. @exception_catch()
  964. def show_describe():
  965. describe = API.get_des_bool_gui()
  966. name = API.get_sheet_name_gui()
  967. title = f"CoTan数据处理 表格:{name}_describe"
  968. data = str(machine_controller.describe(name, describe))
  969. API.vitables_gui(data, title)
  970. API.update_sheet_box_gui()
  971. @staticmethod
  972. @exception_catch()
  973. def show_sheet():
  974. name = API.get_sheet_name_gui()
  975. title = f"CoTan数据处理 表格:{name}"
  976. data = str(machine_controller.get_sheet(name))
  977. API.vitables_gui(data, title)
  978. @staticmethod
  979. @exception_catch()
  980. def get_column(): # 列名(横行竖列,列名是上面的)
  981. name = API.get_sheet_name_gui()
  982. API.update_index_box_gui(machine_controller.get_column(name))
  983. @staticmethod
  984. @exception_catch()
  985. def get_row(): # 行名(横行竖列,行名左)
  986. name = API.get_sheet_name_gui()
  987. API.update_index_box_gui(machine_controller.get_index(name))
  988. @staticmethod
  989. @exception_catch()
  990. def show_one_sheet_html():
  991. global PATH, to_html_type
  992. html_dir = f"{PATH}{os.sep}$Show_Sheet.html"
  993. name = API.get_sheet_name_gui()
  994. assert not name is None
  995. machine_controller.render_html_one(name, html_dir)
  996. webbrowser.open(html_dir)
  997. @staticmethod
  998. @exception_catch()
  999. def show_sheet_html():
  1000. global PATH, to_html_type
  1001. html_dir = f"{PATH}{os.sep}$Show_Sheet.html"
  1002. name = API.get_sheet_name_gui()
  1003. assert not name is None
  1004. machine_controller.render_html_all(name, html_dir, to_html_type.get())
  1005. webbrowser.open(html_dir)
  1006. @staticmethod
  1007. @exception_catch()
  1008. def to_csv():
  1009. global SCREEN, sep, encoding, str_must, index_must
  1010. csv_sep, save_dir = API.to_csv_gui()
  1011. name = API.get_sheet_name_gui()
  1012. machine_controller.to_csv(name, save_dir, csv_sep)
  1013. API.update_sheet_box_gui()
  1014. @staticmethod
  1015. @exception_catch()
  1016. def add_csv():
  1017. global SCREEN, sep, encoding, str_must, index_must, sheet_name
  1018. csv_encoding, csv_sep, file_dir, index, name, str_ = API.add_csv_gui()
  1019. machine_controller.add_csv(file_dir, name, csv_sep, csv_encoding, str_, index)
  1020. API.update_sheet_box_gui()
  1021. @staticmethod
  1022. @exception_catch()
  1023. def add_from_python():
  1024. global SCREEN, sep, encoding, str_must, index_must
  1025. code, name = API.add_from_python_gui()
  1026. machine_controller.add_python(code, name)
  1027. API.update_sheet_box_gui()
  1028. def machine_learning(in_queue, out_queue):
  1029. global SCREEN
  1030. queue_controller.set_queue(in_queue, out_queue)
  1031. queue_controller()
  1032. SCREEN.mainloop()
  1033. queue_controller.stop_process()
  1034. tkinter.Button(
  1035. SCREEN,
  1036. bg=buttom_bg_color,
  1037. fg=word_color,
  1038. text="导入CSV",
  1039. command=API.add_csv,
  1040. font=FONT,
  1041. width=gui_width,
  1042. height=gui_height,
  1043. ).grid(
  1044. column=column,
  1045. row=row,
  1046. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1047. )
  1048. tkinter.Button(
  1049. SCREEN,
  1050. bg=buttom_bg_color,
  1051. fg=word_color,
  1052. text="导入Py",
  1053. command=API.add_from_python,
  1054. font=FONT,
  1055. width=gui_width,
  1056. height=gui_height,
  1057. ).grid(
  1058. column=column + 1,
  1059. row=row,
  1060. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1061. )
  1062. tkinter.Button(
  1063. SCREEN,
  1064. bg=buttom_bg_color,
  1065. fg=word_color,
  1066. text="导出CSV",
  1067. command=API.to_csv,
  1068. font=FONT,
  1069. width=gui_width,
  1070. height=gui_height,
  1071. ).grid(
  1072. column=column + 2,
  1073. row=row,
  1074. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1075. )
  1076. row += 1
  1077. tkinter.Label(
  1078. SCREEN,
  1079. text="表格名称:",
  1080. bg=bg_color,
  1081. fg=word_color,
  1082. font=FONT,
  1083. width=gui_width,
  1084. height=gui_height,
  1085. ).grid(
  1086. column=column, row=row
  1087. ) # 设置说明
  1088. sheet_name = tkinter.Entry(SCREEN, width=gui_width)
  1089. sheet_name.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1090. row += 1
  1091. tkinter.Button(
  1092. SCREEN,
  1093. bg=buttom_bg_color,
  1094. fg=word_color,
  1095. text="删除表格",
  1096. command=API.del_form,
  1097. font=FONT,
  1098. width=gui_width,
  1099. height=gui_height,
  1100. ).grid(
  1101. column=column,
  1102. row=row,
  1103. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1104. )
  1105. tkinter.Button(
  1106. SCREEN,
  1107. bg=buttom_bg_color,
  1108. fg=word_color,
  1109. text="查看表格",
  1110. command=API.show_sheet_html,
  1111. font=FONT,
  1112. width=gui_width,
  1113. height=gui_height,
  1114. ).grid(
  1115. column=column + 1,
  1116. row=row,
  1117. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1118. )
  1119. tkinter.Button(
  1120. SCREEN,
  1121. bg=buttom_bg_color,
  1122. fg=word_color,
  1123. text="查看单一表格",
  1124. command=API.show_one_sheet_html,
  1125. font=FONT,
  1126. width=gui_width,
  1127. height=gui_height,
  1128. ).grid(
  1129. column=column + 2,
  1130. row=row,
  1131. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1132. )
  1133. row += 1
  1134. to_html_type = tkinter.IntVar() # 正,负,0
  1135. lable = ["选项卡型", "可移动型", "自适应型"] # 复选框
  1136. for i in range(3):
  1137. tkinter.Radiobutton(
  1138. SCREEN,
  1139. bg=bg_color,
  1140. fg=word_color,
  1141. activebackground=bg_color,
  1142. activeforeground=word_color,
  1143. selectcolor=bg_color,
  1144. text=lable[i],
  1145. variable=to_html_type,
  1146. value=i,
  1147. ).grid(column=column + i, row=row, sticky=tkinter.W)
  1148. str_must = tkinter.IntVar()
  1149. index_must = tkinter.IntVar()
  1150. row += 1
  1151. tkinter.Label(
  1152. SCREEN,
  1153. text="编码方式:",
  1154. bg=bg_color,
  1155. fg=word_color,
  1156. font=FONT,
  1157. width=gui_width,
  1158. height=gui_height,
  1159. ).grid(
  1160. column=column, row=row
  1161. ) # 设置说明
  1162. encoding = tkinter.Entry(SCREEN, width=gui_width)
  1163. encoding.grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1164. buttom = tkinter.Checkbutton(
  1165. SCREEN,
  1166. bg=bg_color,
  1167. fg=word_color,
  1168. activebackground=bg_color,
  1169. activeforeground=word_color,
  1170. selectcolor=bg_color,
  1171. text="字符串类型",
  1172. variable=str_must,
  1173. )
  1174. buttom.grid(column=column + 2, row=row, sticky=tkinter.W)
  1175. row += 1
  1176. tkinter.Label(
  1177. SCREEN,
  1178. text="CSV分隔符:",
  1179. bg=bg_color,
  1180. fg=word_color,
  1181. font=FONT,
  1182. width=gui_width,
  1183. height=gui_height,
  1184. ).grid(
  1185. column=column, row=row
  1186. ) # 设置说明
  1187. sep = tkinter.Entry(SCREEN, width=gui_width)
  1188. sep.grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1189. tkinter.Checkbutton(
  1190. SCREEN,
  1191. bg=bg_color,
  1192. fg=word_color,
  1193. activebackground=bg_color,
  1194. activeforeground=word_color,
  1195. selectcolor=bg_color,
  1196. text="重置列名",
  1197. variable=index_must,
  1198. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  1199. row += 1
  1200. sheet_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 5) # 显示符号
  1201. sheet_box.grid(
  1202. column=column,
  1203. row=row,
  1204. columnspan=3,
  1205. rowspan=5,
  1206. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  1207. )
  1208. row += 5
  1209. tkinter.Button(
  1210. SCREEN,
  1211. bg=buttom_bg_color,
  1212. fg=word_color,
  1213. text="查看行名",
  1214. command=API.get_row,
  1215. font=FONT,
  1216. width=gui_width,
  1217. height=gui_height,
  1218. ).grid(
  1219. column=column,
  1220. row=row,
  1221. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1222. )
  1223. tkinter.Button(
  1224. SCREEN,
  1225. bg=buttom_bg_color,
  1226. fg=word_color,
  1227. text="查看列名",
  1228. command=API.get_column,
  1229. font=FONT,
  1230. width=gui_width,
  1231. height=gui_height,
  1232. ).grid(
  1233. column=column + 1,
  1234. row=row,
  1235. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1236. )
  1237. tkinter.Button(
  1238. SCREEN,
  1239. bg=buttom_bg_color,
  1240. fg=word_color,
  1241. text="显示表格",
  1242. command=API.show_sheet,
  1243. font=FONT,
  1244. width=gui_width,
  1245. height=gui_height,
  1246. ).grid(
  1247. column=column + 2,
  1248. row=row,
  1249. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1250. )
  1251. row += 1
  1252. tkinter.Label(
  1253. SCREEN,
  1254. text="最大显示行数:",
  1255. bg=bg_color,
  1256. fg=word_color,
  1257. font=FONT,
  1258. width=gui_width,
  1259. height=gui_height,
  1260. ).grid(
  1261. column=column, row=row
  1262. ) # 设置说明
  1263. max_row = tkinter.Entry(SCREEN, width=gui_width * 2)
  1264. max_row.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1265. row += 1
  1266. tkinter.Label(
  1267. SCREEN,
  1268. text="最大显示列数:",
  1269. bg=bg_color,
  1270. fg=word_color,
  1271. font=FONT,
  1272. width=gui_width,
  1273. height=gui_height,
  1274. ).grid(
  1275. column=column, row=row
  1276. ) # 设置说明
  1277. max_column = tkinter.Entry(SCREEN, width=gui_width * 2)
  1278. max_column.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1279. # Row与Column Row是横行,tkinter布局中Row变大,表示所在行数变大,向下移动如:
  1280. # 1,2,3,4,5,6
  1281. # 7,8,9,a,b,c
  1282. # 其中数字1-6是第一行,1-c是第二行,第二行在第一行下面,row变大向下移动(Row是横向行而不是横向移动) to 搞不清楚横行竖列的人
  1283. row += 1
  1284. index_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 10) # 显示符号
  1285. index_box.grid(
  1286. column=column,
  1287. row=row,
  1288. columnspan=3,
  1289. rowspan=10,
  1290. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  1291. )
  1292. row += 10
  1293. tkinter.Button(
  1294. SCREEN,
  1295. bg=buttom_bg_color,
  1296. fg=word_color,
  1297. text="查看数据分析",
  1298. command=API.show_report,
  1299. font=FONT,
  1300. width=gui_width,
  1301. height=gui_height,
  1302. ).grid(
  1303. column=column,
  1304. row=row,
  1305. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1306. )
  1307. tkinter.Button(
  1308. SCREEN,
  1309. bg=buttom_bg_color,
  1310. fg=word_color,
  1311. text="简单数据统计",
  1312. command=API.show_describe,
  1313. font=FONT,
  1314. width=gui_width,
  1315. height=gui_height,
  1316. ).grid(
  1317. column=column + 1,
  1318. row=row,
  1319. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1320. )
  1321. des_bool = tkinter.IntVar() # 是否启用
  1322. tkinter.Checkbutton(
  1323. SCREEN,
  1324. bg=bg_color,
  1325. fg=word_color,
  1326. activebackground=bg_color,
  1327. activeforeground=word_color,
  1328. selectcolor=bg_color,
  1329. text="生成统计表格",
  1330. variable=des_bool,
  1331. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  1332. column += 3
  1333. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  1334. column=column, row=row
  1335. ) # 设置说明
  1336. column += 1
  1337. row = 0
  1338. tkinter.Label(
  1339. SCREEN,
  1340. text="【数据清洗】",
  1341. bg=bg_color,
  1342. fg=word_color,
  1343. font=FONT,
  1344. width=gui_width * 3,
  1345. height=gui_height,
  1346. ).grid(
  1347. column=column,
  1348. columnspan=3,
  1349. row=row,
  1350. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1351. ) # 设置说明
  1352. column_clist = []
  1353. row_clist = []
  1354. label = ["启始(列号):", "终止(列):", "间隔(列):"]
  1355. for i in range(3):
  1356. row += 1
  1357. tkinter.Label(
  1358. SCREEN,
  1359. text=label[i],
  1360. bg=bg_color,
  1361. fg=word_color,
  1362. font=FONT,
  1363. width=gui_width,
  1364. height=gui_height,
  1365. ).grid(
  1366. column=column, row=row
  1367. ) # 设置说明
  1368. column_clist.append(tkinter.Entry(SCREEN, width=gui_width * 2))
  1369. column_clist[-1].grid(
  1370. column=column + 1, row=row, columnspan=2, sticky=tkinter.W + tkinter.E
  1371. )
  1372. label = ["启始(行号):", "终止(行):", "间隔(行):"]
  1373. for i in range(3):
  1374. row += 1
  1375. tkinter.Label(
  1376. SCREEN,
  1377. text=label[i],
  1378. bg=bg_color,
  1379. fg=word_color,
  1380. font=FONT,
  1381. width=gui_width,
  1382. height=gui_height,
  1383. ).grid(
  1384. column=column, row=row
  1385. ) # 设置说明
  1386. row_clist.append(tkinter.Entry(SCREEN, width=gui_width * 2))
  1387. row_clist[-1].grid(
  1388. column=column + 1, row=row, columnspan=2, sticky=tkinter.W + tkinter.E
  1389. )
  1390. row += 1
  1391. column_type = tkinter.IntVar()
  1392. lable = ["根据列号", "根据列名", "输入列号"] # 复选框
  1393. for i in range(3):
  1394. tkinter.Radiobutton(
  1395. SCREEN,
  1396. bg=bg_color,
  1397. fg=word_color,
  1398. activebackground=bg_color,
  1399. activeforeground=word_color,
  1400. selectcolor=bg_color,
  1401. text=lable[i],
  1402. variable=column_type,
  1403. value=i,
  1404. ).grid(column=column + i, row=row, sticky=tkinter.W)
  1405. row += 1
  1406. row_type = tkinter.IntVar()
  1407. lable = ["根据行号", "根据行名", "输入行号"] # 复选框
  1408. for i in range(3):
  1409. tkinter.Radiobutton(
  1410. SCREEN,
  1411. bg=bg_color,
  1412. fg=word_color,
  1413. activebackground=bg_color,
  1414. activeforeground=word_color,
  1415. selectcolor=bg_color,
  1416. text=lable[i],
  1417. variable=row_type,
  1418. value=i,
  1419. ).grid(column=column + i, row=row, sticky=tkinter.W)
  1420. row += 1
  1421. slice_new = tkinter.IntVar()
  1422. tkinter.Button(
  1423. SCREEN,
  1424. bg=buttom_bg_color,
  1425. fg=word_color,
  1426. text="切片选定",
  1427. command=API.slice_data,
  1428. font=FONT,
  1429. width=gui_width,
  1430. height=gui_height,
  1431. ).grid(
  1432. column=column,
  1433. row=row,
  1434. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1435. )
  1436. tkinter.Button(
  1437. SCREEN,
  1438. bg=buttom_bg_color,
  1439. fg=word_color,
  1440. text="删除选定",
  1441. command=API.del_data,
  1442. font=FONT,
  1443. width=gui_width,
  1444. height=gui_height,
  1445. ).grid(
  1446. column=column + 1,
  1447. row=row,
  1448. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1449. )
  1450. tkinter.Checkbutton(
  1451. SCREEN,
  1452. bg=bg_color,
  1453. fg=word_color,
  1454. activebackground=bg_color,
  1455. activeforeground=word_color,
  1456. selectcolor=bg_color,
  1457. text="生成新表格",
  1458. variable=slice_new,
  1459. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  1460. row += 1
  1461. tkinter.Label(
  1462. SCREEN,
  1463. text="布尔逻辑:",
  1464. bg=bg_color,
  1465. fg=word_color,
  1466. font=FONT,
  1467. width=gui_width,
  1468. height=gui_height,
  1469. ).grid(
  1470. column=column,
  1471. row=row,
  1472. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1473. ) # 设置说明
  1474. bool_exp = tkinter.Entry(SCREEN, width=gui_width * 2)
  1475. bool_exp.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.W + tkinter.E)
  1476. row += 1
  1477. tkinter.Label(
  1478. SCREEN,
  1479. text="操作的列号:",
  1480. bg=bg_color,
  1481. fg=word_color,
  1482. font=FONT,
  1483. width=gui_width,
  1484. height=gui_height,
  1485. ).grid(
  1486. column=column,
  1487. row=row,
  1488. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1489. ) # 设置说明
  1490. drop_column = tkinter.Entry(SCREEN, width=gui_width * 2)
  1491. drop_column.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.W + tkinter.E)
  1492. row += 1
  1493. tkinter.Button(
  1494. SCREEN,
  1495. bg=buttom_bg_color,
  1496. fg=word_color,
  1497. text="生成布尔表格",
  1498. command=API.to_bool,
  1499. font=FONT,
  1500. width=gui_width,
  1501. height=gui_height,
  1502. ).grid(
  1503. column=column,
  1504. row=row,
  1505. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1506. )
  1507. tkinter.Button(
  1508. SCREEN,
  1509. bg=buttom_bg_color,
  1510. fg=word_color,
  1511. text="查看空值",
  1512. command=API.is_nan,
  1513. font=FONT,
  1514. width=gui_width,
  1515. height=gui_height,
  1516. ).grid(
  1517. column=column + 1,
  1518. row=row,
  1519. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1520. )
  1521. tkinter.Button(
  1522. SCREEN,
  1523. bg=buttom_bg_color,
  1524. fg=word_color,
  1525. text="清洗空值(按行)",
  1526. command=API.clean_nan_row,
  1527. font=FONT,
  1528. width=gui_width,
  1529. height=gui_height,
  1530. ).grid(
  1531. column=column + 2,
  1532. row=row,
  1533. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1534. )
  1535. row += 1
  1536. tkinter.Button(
  1537. SCREEN,
  1538. bg=buttom_bg_color,
  1539. fg=word_color,
  1540. text="添加执行方法",
  1541. command=API.add_cleaning_script,
  1542. font=FONT,
  1543. width=gui_width,
  1544. height=gui_height,
  1545. ).grid(
  1546. column=column,
  1547. row=row,
  1548. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1549. )
  1550. tkinter.Button(
  1551. SCREEN,
  1552. bg=buttom_bg_color,
  1553. fg=word_color,
  1554. text="删除执行方法",
  1555. command=API.del_cleaning_script,
  1556. font=FONT,
  1557. width=gui_width,
  1558. height=gui_height,
  1559. ).grid(
  1560. column=column + 1,
  1561. row=row,
  1562. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1563. )
  1564. tkinter.Button(
  1565. SCREEN,
  1566. bg=buttom_bg_color,
  1567. fg=word_color,
  1568. text="数据特征提取",
  1569. command=API.feature_extraction,
  1570. font=FONT,
  1571. width=gui_width,
  1572. height=gui_height,
  1573. ).grid(
  1574. column=column + 2,
  1575. row=row,
  1576. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1577. )
  1578. row += 1
  1579. clean_func_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 2)
  1580. clean_func_box.grid(
  1581. column=column,
  1582. row=row,
  1583. columnspan=3,
  1584. rowspan=2,
  1585. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  1586. )
  1587. row += 2
  1588. tkinter.Button(
  1589. SCREEN,
  1590. bg=buttom_bg_color,
  1591. fg=word_color,
  1592. text="查看词典",
  1593. command=API.show_dictionary_gui,
  1594. font=FONT,
  1595. width=gui_width,
  1596. height=gui_height,
  1597. ).grid(
  1598. column=column,
  1599. row=row,
  1600. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1601. )
  1602. tkinter.Button(
  1603. SCREEN,
  1604. bg=buttom_bg_color,
  1605. fg=word_color,
  1606. text="恢复显示",
  1607. command=API.reset_clean_code_gui,
  1608. font=FONT,
  1609. width=gui_width,
  1610. height=gui_height,
  1611. ).grid(
  1612. column=column + 1,
  1613. row=row,
  1614. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1615. )
  1616. tkinter.Button(
  1617. SCREEN,
  1618. bg=buttom_bg_color,
  1619. fg=word_color,
  1620. text="执行数据清洗",
  1621. command=API.execute_cleaning_script,
  1622. font=FONT,
  1623. width=gui_width,
  1624. height=gui_height,
  1625. ).grid(
  1626. column=column + 2,
  1627. row=row,
  1628. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1629. )
  1630. row += 1
  1631. clean_code = tkinter.Text(SCREEN, width=gui_width * 3, height=gui_height * 7)
  1632. clean_code.grid(
  1633. column=column,
  1634. row=row,
  1635. columnspan=3,
  1636. rowspan=7,
  1637. sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S,
  1638. )
  1639. clean_code.insert("0.0", clean_default_script)
  1640. row += 7
  1641. tkinter.Button(
  1642. SCREEN,
  1643. bg=buttom_bg_color,
  1644. fg=word_color,
  1645. text="清空执行方法",
  1646. command=API.empty_cleaning_script,
  1647. font=FONT,
  1648. width=gui_width,
  1649. height=gui_height,
  1650. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1651. tkinter.Button(
  1652. SCREEN,
  1653. bg=buttom_bg_color,
  1654. fg=word_color,
  1655. text="查看执行方法",
  1656. command=API.view_cleaning_script,
  1657. font=FONT,
  1658. width=gui_width,
  1659. height=gui_height,
  1660. ).grid(
  1661. column=column + 1,
  1662. row=row,
  1663. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1664. )
  1665. tkinter.Button(
  1666. SCREEN,
  1667. bg=buttom_bg_color,
  1668. fg=word_color,
  1669. text="导入执行方法",
  1670. command=API.open_python_for_clean_gui,
  1671. font=FONT,
  1672. width=gui_width,
  1673. height=gui_height,
  1674. ).grid(
  1675. column=column + 2,
  1676. row=row,
  1677. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1678. )
  1679. column += 3
  1680. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  1681. column=column, row=row
  1682. ) # 设置说明
  1683. column += 1
  1684. row = 0
  1685. tkinter.Label(
  1686. SCREEN,
  1687. text="【数据可视化】",
  1688. bg=bg_color,
  1689. fg=word_color,
  1690. font=FONT,
  1691. width=gui_width * 3,
  1692. height=gui_height,
  1693. ).grid(
  1694. column=column,
  1695. columnspan=3,
  1696. row=row,
  1697. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1698. ) # 设置说明
  1699. row += 1
  1700. tkinter.Button(
  1701. SCREEN,
  1702. bg=buttom_bg_color,
  1703. fg=word_color,
  1704. text="生成柱状图",
  1705. command=API.to_bar,
  1706. font=FONT,
  1707. width=gui_width,
  1708. height=gui_height,
  1709. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1710. tkinter.Button(
  1711. SCREEN,
  1712. bg=buttom_bg_color,
  1713. fg=word_color,
  1714. text="生成3D柱状图",
  1715. command=API.to_bar3d,
  1716. font=FONT,
  1717. width=gui_width,
  1718. height=gui_height,
  1719. ).grid(
  1720. column=column + 1,
  1721. row=row,
  1722. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1723. )
  1724. tkinter.Button(
  1725. SCREEN,
  1726. bg=buttom_bg_color,
  1727. fg=word_color,
  1728. text="生成折线图",
  1729. command=API.to_line,
  1730. font=FONT,
  1731. width=gui_width,
  1732. height=gui_height,
  1733. ).grid(
  1734. column=column + 2,
  1735. row=row,
  1736. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1737. )
  1738. row += 1
  1739. tkinter.Button(
  1740. SCREEN,
  1741. bg=buttom_bg_color,
  1742. fg=word_color,
  1743. text="生成3D折线图",
  1744. command=API.to_line3d,
  1745. font=FONT,
  1746. width=gui_width,
  1747. height=gui_height,
  1748. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1749. tkinter.Button(
  1750. SCREEN,
  1751. bg=buttom_bg_color,
  1752. fg=word_color,
  1753. text="生成象形柱状图",
  1754. command=API.to_pictorialbar,
  1755. font=FONT,
  1756. width=gui_width,
  1757. height=gui_height,
  1758. ).grid(
  1759. column=column + 1,
  1760. row=row,
  1761. columnspan=2,
  1762. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  1763. )
  1764. row += 1
  1765. tkinter.Button(
  1766. SCREEN,
  1767. bg=buttom_bg_color,
  1768. fg=word_color,
  1769. text="生成散点图",
  1770. command=API.to_scatter,
  1771. font=FONT,
  1772. width=gui_width,
  1773. height=gui_height,
  1774. ).grid(
  1775. column=column,
  1776. row=row,
  1777. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1778. )
  1779. tkinter.Button(
  1780. SCREEN,
  1781. bg=buttom_bg_color,
  1782. fg=word_color,
  1783. text="生成3D散点图",
  1784. command=API.to_scatter3d,
  1785. font=FONT,
  1786. width=gui_width,
  1787. height=gui_height,
  1788. ).grid(
  1789. column=column + 1,
  1790. row=row,
  1791. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1792. )
  1793. tkinter.Button(
  1794. SCREEN,
  1795. bg=buttom_bg_color,
  1796. fg=word_color,
  1797. text="生成箱形图",
  1798. command=API.to_boxpolt,
  1799. font=FONT,
  1800. width=gui_width,
  1801. height=gui_height,
  1802. ).grid(
  1803. column=column + 2,
  1804. row=row,
  1805. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1806. )
  1807. row += 1
  1808. tkinter.Button(
  1809. SCREEN,
  1810. bg=buttom_bg_color,
  1811. fg=word_color,
  1812. text="生成漏斗图",
  1813. command=API.to_funnel,
  1814. font=FONT,
  1815. width=gui_width,
  1816. height=gui_height,
  1817. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1818. tkinter.Button(
  1819. SCREEN,
  1820. bg=buttom_bg_color,
  1821. fg=word_color,
  1822. text="生成热力图",
  1823. command=API.to_heat_map,
  1824. font=FONT,
  1825. width=gui_width,
  1826. height=gui_height,
  1827. ).grid(
  1828. column=column + 1,
  1829. row=row,
  1830. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1831. )
  1832. tkinter.Button(
  1833. SCREEN,
  1834. bg=buttom_bg_color,
  1835. fg=word_color,
  1836. text="生成饼图",
  1837. command=API.to_pie,
  1838. font=FONT,
  1839. width=gui_width,
  1840. height=gui_height,
  1841. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1842. row += 1
  1843. tkinter.Button(
  1844. SCREEN,
  1845. bg=buttom_bg_color,
  1846. fg=word_color,
  1847. text="生成多轴图",
  1848. command=API.to_parallel,
  1849. font=FONT,
  1850. width=gui_width,
  1851. height=gui_height,
  1852. ).grid(
  1853. column=column,
  1854. row=row,
  1855. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1856. )
  1857. tkinter.Button(
  1858. SCREEN,
  1859. bg=buttom_bg_color,
  1860. fg=word_color,
  1861. text="生成极坐标图",
  1862. command=API.to_polar,
  1863. font=FONT,
  1864. width=gui_width,
  1865. height=gui_height,
  1866. ).grid(
  1867. column=column + 1,
  1868. row=row,
  1869. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1870. )
  1871. tkinter.Button(
  1872. SCREEN,
  1873. bg=buttom_bg_color,
  1874. fg=word_color,
  1875. text="生成雷达图",
  1876. command=API.to_radar,
  1877. font=FONT,
  1878. width=gui_width,
  1879. height=gui_height,
  1880. ).grid(
  1881. column=column + 2,
  1882. row=row,
  1883. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1884. )
  1885. row += 1
  1886. tkinter.Button(
  1887. SCREEN,
  1888. bg=buttom_bg_color,
  1889. fg=word_color,
  1890. text="生成词云",
  1891. command=API.to_word_cloud,
  1892. font=FONT,
  1893. width=gui_width,
  1894. height=gui_height,
  1895. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1896. tkinter.Button(
  1897. SCREEN,
  1898. bg=buttom_bg_color,
  1899. fg=word_color,
  1900. text="生成关系图",
  1901. command=API.to_format_graph,
  1902. font=FONT,
  1903. width=gui_width,
  1904. height=gui_height,
  1905. ).grid(
  1906. column=column + 1,
  1907. row=row,
  1908. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1909. )
  1910. tkinter.Button(
  1911. SCREEN,
  1912. bg=buttom_bg_color,
  1913. fg=word_color,
  1914. text="生成XY关系图",
  1915. command=API.to_graph,
  1916. font=FONT,
  1917. width=gui_width,
  1918. height=gui_height,
  1919. ).grid(
  1920. column=column + 2,
  1921. row=row,
  1922. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1923. )
  1924. row += 1
  1925. tkinter.Button(
  1926. SCREEN,
  1927. bg=buttom_bg_color,
  1928. fg=word_color,
  1929. text="生成水球图",
  1930. command=API.to_liquid,
  1931. font=FONT,
  1932. width=gui_width,
  1933. height=gui_height,
  1934. ).grid(
  1935. column=column,
  1936. row=row,
  1937. columnspan=2,
  1938. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  1939. )
  1940. tkinter.Button(
  1941. SCREEN,
  1942. bg=buttom_bg_color,
  1943. fg=word_color,
  1944. text="生成仪表图",
  1945. command=API.to_gauge,
  1946. font=FONT,
  1947. width=gui_width,
  1948. height=gui_height,
  1949. ).grid(
  1950. column=column + 2,
  1951. row=row,
  1952. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1953. )
  1954. row += 1
  1955. tkinter.Button(
  1956. SCREEN,
  1957. bg=buttom_bg_color,
  1958. fg=word_color,
  1959. text="生成日历图",
  1960. command=API.to_calendar,
  1961. font=FONT,
  1962. width=gui_width,
  1963. height=gui_height,
  1964. ).grid(
  1965. column=column,
  1966. row=row,
  1967. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1968. )
  1969. tkinter.Button(
  1970. SCREEN,
  1971. bg=buttom_bg_color,
  1972. fg=word_color,
  1973. text="生成河流图",
  1974. command=API.to_theme_river,
  1975. font=FONT,
  1976. width=gui_width,
  1977. height=gui_height,
  1978. ).grid(
  1979. column=column + 1,
  1980. row=row,
  1981. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1982. )
  1983. tkinter.Button(
  1984. SCREEN,
  1985. bg=buttom_bg_color,
  1986. fg=word_color,
  1987. text="生成旭日图",
  1988. command=API.to_sunburst,
  1989. font=FONT,
  1990. width=gui_width,
  1991. height=gui_height,
  1992. ).grid(
  1993. column=column + 2,
  1994. row=row,
  1995. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1996. )
  1997. row += 1
  1998. tkinter.Button(
  1999. SCREEN,
  2000. bg=buttom_bg_color,
  2001. fg=word_color,
  2002. text="生成桑基图",
  2003. command=API.to_sankey,
  2004. font=FONT,
  2005. width=gui_width,
  2006. height=gui_height,
  2007. ).grid(
  2008. column=column,
  2009. row=row,
  2010. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2011. )
  2012. tkinter.Button(
  2013. SCREEN,
  2014. bg=buttom_bg_color,
  2015. fg=word_color,
  2016. text="生成树状图",
  2017. command=API.to_tree,
  2018. font=FONT,
  2019. width=gui_width,
  2020. height=gui_height,
  2021. ).grid(
  2022. column=column + 1,
  2023. row=row,
  2024. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2025. )
  2026. tkinter.Button(
  2027. SCREEN,
  2028. bg=buttom_bg_color,
  2029. fg=word_color,
  2030. text="生成矩形树图",
  2031. command=API.to_treemap,
  2032. font=FONT,
  2033. width=gui_width,
  2034. height=gui_height,
  2035. ).grid(
  2036. column=column + 2,
  2037. row=row,
  2038. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2039. )
  2040. row += 1
  2041. tkinter.Button(
  2042. SCREEN,
  2043. bg=buttom_bg_color,
  2044. fg=word_color,
  2045. text="生成Map地图",
  2046. command=API.to_map,
  2047. font=FONT,
  2048. width=gui_width,
  2049. height=gui_height,
  2050. ).grid(
  2051. column=column,
  2052. row=row,
  2053. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2054. )
  2055. tkinter.Button(
  2056. SCREEN,
  2057. bg=buttom_bg_color,
  2058. fg=word_color,
  2059. text="生成Geo点地图",
  2060. command=API.to_scattergeo,
  2061. font=FONT,
  2062. width=gui_width,
  2063. height=gui_height,
  2064. ).grid(
  2065. column=column + 1,
  2066. row=row,
  2067. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2068. )
  2069. tkinter.Button(
  2070. SCREEN,
  2071. bg=buttom_bg_color,
  2072. fg=word_color,
  2073. text="生成Geo地图",
  2074. command=API.to_geo,
  2075. font=FONT,
  2076. width=gui_width,
  2077. height=gui_height,
  2078. ).grid(
  2079. column=column + 2,
  2080. row=row,
  2081. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2082. )
  2083. row += 1
  2084. tkinter.Button(
  2085. SCREEN,
  2086. bg=buttom_bg_color,
  2087. fg=word_color,
  2088. text="选择底图",
  2089. command=API.add_basemap,
  2090. font=FONT,
  2091. width=gui_width,
  2092. height=gui_height,
  2093. ).grid(
  2094. column=column,
  2095. row=row,
  2096. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2097. )
  2098. tkinter.Button(
  2099. SCREEN,
  2100. bg=buttom_bg_color,
  2101. fg=word_color,
  2102. text="选择顶图",
  2103. command=API.add_top_image,
  2104. font=FONT,
  2105. width=gui_width,
  2106. height=gui_height,
  2107. ).grid(
  2108. column=column + 1,
  2109. row=row,
  2110. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2111. )
  2112. tkinter.Button(
  2113. SCREEN,
  2114. bg=buttom_bg_color,
  2115. fg=word_color,
  2116. text="生成层叠图",
  2117. command=API.make_overlap,
  2118. font=FONT,
  2119. width=gui_width,
  2120. height=gui_height,
  2121. ).grid(
  2122. column=column + 2,
  2123. row=row,
  2124. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2125. )
  2126. row += 1
  2127. overlap_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 2)
  2128. overlap_box.grid(
  2129. column=column,
  2130. row=row,
  2131. columnspan=3,
  2132. rowspan=2,
  2133. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  2134. )
  2135. row += 1
  2136. tkinter.Button(
  2137. SCREEN,
  2138. bg=buttom_bg_color,
  2139. fg=word_color,
  2140. text="渲染HTML",
  2141. command=API.rendering,
  2142. font=FONT,
  2143. width=gui_width,
  2144. height=gui_height,
  2145. ).grid(
  2146. column=column,
  2147. row=row,
  2148. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2149. )
  2150. tkinter.Button(
  2151. SCREEN,
  2152. bg=buttom_bg_color,
  2153. fg=word_color,
  2154. text="单独渲染HTML",
  2155. command=API.rendering_one,
  2156. font=FONT,
  2157. width=gui_width,
  2158. height=gui_height,
  2159. ).grid(
  2160. column=column + 1,
  2161. row=row,
  2162. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2163. )
  2164. tkinter.Button(
  2165. SCREEN,
  2166. bg=buttom_bg_color,
  2167. fg=word_color,
  2168. text="删除渲染",
  2169. command=API.del_rendering,
  2170. font=FONT,
  2171. width=gui_width,
  2172. height=gui_height,
  2173. ).grid(
  2174. column=column + 2,
  2175. row=row,
  2176. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2177. )
  2178. row += 1
  2179. render_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height)
  2180. render_box.grid(
  2181. column=column,
  2182. row=row,
  2183. columnspan=3,
  2184. rowspan=2,
  2185. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  2186. )
  2187. row += 2
  2188. draw_as_well = tkinter.IntVar()
  2189. tkinter.Button(
  2190. SCREEN,
  2191. bg=buttom_bg_color,
  2192. fg=word_color,
  2193. text="清空渲染",
  2194. command=API.clear_rendering,
  2195. font=FONT,
  2196. width=gui_width,
  2197. height=gui_height,
  2198. ).grid(
  2199. column=column,
  2200. row=row,
  2201. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2202. )
  2203. tkinter.Button(
  2204. SCREEN,
  2205. bg=buttom_bg_color,
  2206. fg=word_color,
  2207. text="导入渲染",
  2208. command=API.python_render,
  2209. font=FONT,
  2210. width=gui_width,
  2211. height=gui_height,
  2212. ).grid(
  2213. column=column + 1,
  2214. row=row,
  2215. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2216. )
  2217. tkinter.Checkbutton(
  2218. SCREEN,
  2219. bg=bg_color,
  2220. fg=word_color,
  2221. activebackground=bg_color,
  2222. activeforeground=word_color,
  2223. selectcolor=bg_color,
  2224. text="马上渲染",
  2225. variable=draw_as_well,
  2226. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  2227. row += 1
  2228. rendering_parameters = tkinter.Text(SCREEN, width=gui_width * 3, height=gui_height * 7)
  2229. rendering_parameters.grid(
  2230. column=column,
  2231. row=row,
  2232. columnspan=3,
  2233. rowspan=7,
  2234. sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S,
  2235. )
  2236. row += 7
  2237. tkinter.Button(
  2238. SCREEN,
  2239. bg=buttom_bg_color,
  2240. fg=word_color,
  2241. text="查看词典",
  2242. command=API.show_dictionary_gui,
  2243. font=FONT,
  2244. width=gui_width,
  2245. height=gui_height,
  2246. ).grid(
  2247. column=column,
  2248. row=row,
  2249. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2250. )
  2251. tkinter.Button(
  2252. SCREEN,
  2253. bg=buttom_bg_color,
  2254. fg=word_color,
  2255. text="恢复显示",
  2256. command=API.show_tips_gui,
  2257. font=FONT,
  2258. width=gui_width,
  2259. height=gui_height,
  2260. ).grid(
  2261. column=column + 1,
  2262. row=row,
  2263. columnspan=2,
  2264. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2265. )
  2266. column += 3
  2267. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  2268. column=column, row=row
  2269. ) # 设置说明
  2270. column += 1
  2271. row = 0
  2272. tkinter.Label(
  2273. SCREEN,
  2274. text="【行名与列名】",
  2275. bg=bg_color,
  2276. fg=word_color,
  2277. font=FONT,
  2278. width=gui_width * 3,
  2279. height=gui_height,
  2280. ).grid(
  2281. column=column,
  2282. columnspan=3,
  2283. row=row,
  2284. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2285. ) # 设置说明
  2286. row += 1
  2287. replace_index = tkinter.IntVar()
  2288. lable = ["(列数据)调整行名", "(行数据)调整列名"] # 复选框
  2289. for i in range(2):
  2290. tkinter.Radiobutton(
  2291. SCREEN,
  2292. bg=bg_color,
  2293. fg=word_color,
  2294. activebackground=bg_color,
  2295. activeforeground=word_color,
  2296. selectcolor=bg_color,
  2297. text=lable[i],
  2298. variable=replace_index,
  2299. value=i,
  2300. ).grid(column=column + i, row=row, sticky=tkinter.W)
  2301. tkinter.Button(
  2302. SCREEN,
  2303. bg=buttom_bg_color,
  2304. fg=word_color,
  2305. text="植入行(列)号",
  2306. command=API.num_with_name,
  2307. font=FONT,
  2308. width=gui_width,
  2309. height=gui_height,
  2310. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  2311. row += 1
  2312. replace_type = []
  2313. lable = ["保留原值", "保留新值"] # 复选框
  2314. for i in range(2):
  2315. replace_type.append(tkinter.IntVar())
  2316. tkinter.Checkbutton(
  2317. SCREEN,
  2318. bg=bg_color,
  2319. fg=word_color,
  2320. activebackground=bg_color,
  2321. activeforeground=word_color,
  2322. selectcolor=bg_color,
  2323. text=lable[i],
  2324. variable=replace_type[-1],
  2325. ).grid(column=column + i, row=row, sticky=tkinter.W)
  2326. tkinter.Button(
  2327. SCREEN,
  2328. bg=buttom_bg_color,
  2329. fg=word_color,
  2330. text="统一行(列)号",
  2331. command=API.num_to_name,
  2332. font=FONT,
  2333. width=gui_width,
  2334. height=gui_height,
  2335. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  2336. row += 1
  2337. tkinter.Label(
  2338. SCREEN,
  2339. text="替换字典:",
  2340. bg=bg_color,
  2341. fg=word_color,
  2342. font=FONT,
  2343. width=gui_width,
  2344. height=gui_height,
  2345. ).grid(
  2346. column=column, row=row
  2347. ) # 设置说明
  2348. replace_dict = tkinter.Entry(SCREEN, width=gui_width * 2)
  2349. replace_dict.grid(
  2350. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  2351. )
  2352. row += 1
  2353. tkinter.Label(
  2354. SCREEN,
  2355. text="替换列(行):",
  2356. bg=bg_color,
  2357. fg=word_color,
  2358. font=FONT,
  2359. width=gui_width,
  2360. height=gui_height,
  2361. ).grid(
  2362. column=column, row=row
  2363. ) # 设置说明
  2364. replace_iloc = tkinter.Entry(SCREEN, width=gui_width * 2)
  2365. replace_iloc.grid(
  2366. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  2367. )
  2368. row += 1
  2369. tkinter.Button(
  2370. SCREEN,
  2371. bg=buttom_bg_color,
  2372. fg=word_color,
  2373. text="执行替换已有列(行)操作",
  2374. command=API.change_index,
  2375. font=FONT,
  2376. width=gui_width * 2,
  2377. height=gui_height,
  2378. ).grid(column=column, columnspan=2, row=row, sticky=tkinter.E + tkinter.W)
  2379. tkinter.Button(
  2380. SCREEN,
  2381. bg=buttom_bg_color,
  2382. fg=word_color,
  2383. text="执行替换操作",
  2384. command=API.replace_index_func,
  2385. font=FONT,
  2386. width=gui_width,
  2387. height=gui_height,
  2388. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  2389. label = ["起点", "终点", "间隔"]
  2390. date_input = []
  2391. for i in range(3):
  2392. row += 1
  2393. tkinter.Label(
  2394. SCREEN,
  2395. text="时间序列" + label[i],
  2396. bg=bg_color,
  2397. fg=word_color,
  2398. font=FONT,
  2399. width=gui_width,
  2400. height=gui_height,
  2401. ).grid(
  2402. column=column, row=row
  2403. ) # 设置说明
  2404. date_input.append(tkinter.Entry(SCREEN, width=gui_width * 2))
  2405. date_input[-1].grid(
  2406. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  2407. )
  2408. row += 1
  2409. date_type = tkinter.IntVar()
  2410. tkinter.Button(
  2411. SCREEN,
  2412. bg=buttom_bg_color,
  2413. fg=word_color,
  2414. text="刷入Date序列",
  2415. command=API.date_index,
  2416. font=FONT,
  2417. width=gui_width,
  2418. height=gui_height,
  2419. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  2420. tkinter.Button(
  2421. SCREEN,
  2422. bg=buttom_bg_color,
  2423. fg=word_color,
  2424. text="刷入Time序列",
  2425. command=API.time_index,
  2426. font=FONT,
  2427. width=gui_width,
  2428. height=gui_height,
  2429. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  2430. tkinter.Checkbutton(
  2431. SCREEN,
  2432. bg=bg_color,
  2433. fg=word_color,
  2434. activebackground=bg_color,
  2435. activeforeground=word_color,
  2436. selectcolor=bg_color,
  2437. text="使用间隔",
  2438. variable=date_type,
  2439. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  2440. row += 1
  2441. tkinter.Label(
  2442. SCREEN,
  2443. text="【数据类型管理】",
  2444. bg=bg_color,
  2445. fg=word_color,
  2446. font=FONT,
  2447. width=gui_width * 3,
  2448. height=gui_height,
  2449. ).grid(
  2450. column=column,
  2451. columnspan=3,
  2452. row=row,
  2453. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2454. ) # 设置说明
  2455. row += 1
  2456. tkinter.Label(
  2457. SCREEN,
  2458. text="修改(列号):",
  2459. bg=bg_color,
  2460. fg=word_color,
  2461. font=FONT,
  2462. width=gui_width,
  2463. height=gui_height,
  2464. ).grid(
  2465. column=column, row=row
  2466. ) # 设置说明
  2467. dtype_column = tkinter.Entry(SCREEN, width=gui_width * 2)
  2468. dtype_column.grid(
  2469. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  2470. )
  2471. row += 1
  2472. tkinter.Label(
  2473. SCREEN,
  2474. text="数据类型:",
  2475. bg=bg_color,
  2476. fg=word_color,
  2477. font=FONT,
  2478. width=gui_width,
  2479. height=gui_height,
  2480. ).grid(
  2481. column=column, row=row
  2482. ) # 设置说明
  2483. dtype_input = tkinter.Entry(SCREEN, width=gui_width * 2)
  2484. dtype_input.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  2485. row += 1
  2486. tkinter.Label(
  2487. SCREEN,
  2488. text="错误值:",
  2489. bg=bg_color,
  2490. fg=word_color,
  2491. font=FONT,
  2492. width=gui_width,
  2493. height=gui_height,
  2494. ).grid(
  2495. column=column, row=row
  2496. ) # 设置说明
  2497. dtype_wrong = tkinter.Entry(SCREEN, width=gui_width * 2)
  2498. dtype_wrong.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  2499. row += 1
  2500. tkinter.Button(
  2501. SCREEN,
  2502. bg=buttom_bg_color,
  2503. fg=word_color,
  2504. text="执行转换",
  2505. command=API.set_dtype,
  2506. font=FONT,
  2507. width=gui_width,
  2508. height=gui_height,
  2509. ).grid(
  2510. column=column,
  2511. row=row,
  2512. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2513. )
  2514. dtype_func = tkinter.IntVar() # 正,负,0
  2515. lable = ["硬转换", "软转换"] # 复选框
  2516. for i in range(2):
  2517. tkinter.Radiobutton(
  2518. SCREEN,
  2519. bg=bg_color,
  2520. fg=word_color,
  2521. activebackground=bg_color,
  2522. activeforeground=word_color,
  2523. selectcolor=bg_color,
  2524. text=lable[i],
  2525. variable=dtype_func,
  2526. value=i,
  2527. ).grid(column=column + 1 + i, row=row, sticky=tkinter.W)
  2528. row += 1
  2529. tkinter.Label(
  2530. SCREEN,
  2531. text="【排序操作】",
  2532. bg=bg_color,
  2533. fg=word_color,
  2534. font=FONT,
  2535. width=gui_width * 3,
  2536. height=gui_height,
  2537. ).grid(
  2538. column=column, columnspan=3, row=row
  2539. ) # 设置说明
  2540. row += 1
  2541. tkinter.Button(
  2542. SCREEN,
  2543. bg=buttom_bg_color,
  2544. fg=word_color,
  2545. text=".T",
  2546. command=API.transpose,
  2547. font=FONT,
  2548. width=gui_width,
  2549. height=gui_height,
  2550. ).grid(
  2551. column=column,
  2552. row=row,
  2553. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2554. )
  2555. tkinter.Button(
  2556. SCREEN,
  2557. bg=buttom_bg_color,
  2558. fg=word_color,
  2559. text="按行名排序",
  2560. command=API.sort_by_tow,
  2561. font=FONT,
  2562. width=gui_width,
  2563. height=gui_height,
  2564. ).grid(
  2565. column=column + 1,
  2566. row=row,
  2567. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2568. )
  2569. tkinter.Button(
  2570. SCREEN,
  2571. bg=buttom_bg_color,
  2572. fg=word_color,
  2573. text="按列名排序",
  2574. command=API.sort_by_column,
  2575. font=FONT,
  2576. width=gui_width,
  2577. height=gui_height,
  2578. ).grid(
  2579. column=column + 2,
  2580. row=row,
  2581. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2582. )
  2583. row += 1
  2584. tkinter.Label(
  2585. SCREEN,
  2586. text="基准列(列号):",
  2587. bg=bg_color,
  2588. fg=word_color,
  2589. font=FONT,
  2590. width=gui_width,
  2591. height=gui_height,
  2592. ).grid(
  2593. column=column, row=row
  2594. ) # 设置说明
  2595. sort_by = tkinter.Entry(SCREEN, width=gui_width + 2)
  2596. sort_by.grid(column=column + 1, row=row, sticky=tkinter.W)
  2597. tkinter.Button(
  2598. SCREEN,
  2599. bg=buttom_bg_color,
  2600. fg=word_color,
  2601. text="按数据排序",
  2602. command=API.stored_value,
  2603. font=FONT,
  2604. width=gui_width,
  2605. height=gui_height,
  2606. ).grid(
  2607. column=column + 2,
  2608. row=row,
  2609. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2610. )
  2611. row += 1
  2612. ascending_type = tkinter.IntVar()
  2613. ascending_new = tkinter.IntVar()
  2614. lable = ["正序排列", "倒序排列"] # 复选框
  2615. for i in range(2):
  2616. tkinter.Radiobutton(
  2617. SCREEN,
  2618. bg=bg_color,
  2619. fg=word_color,
  2620. activebackground=bg_color,
  2621. activeforeground=word_color,
  2622. selectcolor=bg_color,
  2623. text=lable[i],
  2624. variable=ascending_type,
  2625. value=i,
  2626. ).grid(column=column + i, row=row, sticky=tkinter.W)
  2627. tkinter.Checkbutton(
  2628. SCREEN,
  2629. bg=bg_color,
  2630. fg=word_color,
  2631. activebackground=bg_color,
  2632. activeforeground=word_color,
  2633. selectcolor=bg_color,
  2634. text="生成新表格",
  2635. variable=ascending_new,
  2636. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  2637. row += 1
  2638. stored_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 4) # 显示符号
  2639. stored_box.grid(
  2640. column=column,
  2641. row=row,
  2642. columnspan=3,
  2643. rowspan=5,
  2644. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  2645. )
  2646. row += 5
  2647. tkinter.Button(
  2648. SCREEN,
  2649. bg=buttom_bg_color,
  2650. fg=word_color,
  2651. text="添加基准",
  2652. command=API.add_baseline,
  2653. font=FONT,
  2654. width=gui_width,
  2655. height=gui_height,
  2656. ).grid(
  2657. column=column,
  2658. row=row,
  2659. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2660. )
  2661. tkinter.Button(
  2662. SCREEN,
  2663. bg=buttom_bg_color,
  2664. fg=word_color,
  2665. text="删除基准",
  2666. command=API.del_baseline,
  2667. font=FONT,
  2668. width=gui_width,
  2669. height=gui_height,
  2670. ).grid(
  2671. column=column + 1,
  2672. row=row,
  2673. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2674. )
  2675. tkinter.Button(
  2676. SCREEN,
  2677. bg=buttom_bg_color,
  2678. fg=word_color,
  2679. text="打乱表格",
  2680. command=API.sample_data,
  2681. font=FONT,
  2682. width=gui_width,
  2683. height=gui_height,
  2684. ).grid(
  2685. column=column + 2,
  2686. row=row,
  2687. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2688. )
  2689. column += 3
  2690. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  2691. column=column, row=row
  2692. ) # 设置说明
  2693. column += 1
  2694. row = 0
  2695. tkinter.Label(
  2696. SCREEN,
  2697. text="【机器学习】",
  2698. bg=bg_color,
  2699. fg=word_color,
  2700. font=FONT,
  2701. width=gui_width * 3,
  2702. height=gui_height,
  2703. ).grid(
  2704. column=column,
  2705. columnspan=3,
  2706. row=row,
  2707. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2708. ) # 设置说明
  2709. row += 1
  2710. chose_learner = tkinter.StringVar()
  2711. put = tkinter.Entry(SCREEN, width=gui_width * 2, textvariable=chose_learner)
  2712. put.grid(column=column, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  2713. put["state"] = "readonly"
  2714. tkinter.Button(
  2715. SCREEN,
  2716. bg=buttom_bg_color,
  2717. fg=word_color,
  2718. text="选用学习器",
  2719. command=API.set_learner_gui,
  2720. font=FONT,
  2721. width=gui_width,
  2722. height=gui_height,
  2723. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  2724. row += 1
  2725. tkinter.Label(
  2726. SCREEN,
  2727. text="测试数据分割:",
  2728. bg=bg_color,
  2729. fg=word_color,
  2730. font=FONT,
  2731. width=gui_width,
  2732. height=gui_height,
  2733. ).grid(column=column, row=row)
  2734. data_split = tkinter.Entry(SCREEN, width=gui_width * 2)
  2735. data_split.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  2736. row += 1
  2737. learner_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 5)
  2738. learner_box.grid(
  2739. column=column,
  2740. row=row,
  2741. columnspan=3,
  2742. rowspan=5,
  2743. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  2744. )
  2745. row += 5
  2746. tkinter.Button(
  2747. SCREEN,
  2748. bg=buttom_bg_color,
  2749. fg=word_color,
  2750. text="导入学习器",
  2751. command=API.rendering,
  2752. font=FONT,
  2753. width=gui_width,
  2754. height=gui_height,
  2755. ).grid(
  2756. column=column,
  2757. row=row,
  2758. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2759. )
  2760. tkinter.Button(
  2761. SCREEN,
  2762. bg=buttom_bg_color,
  2763. fg=word_color,
  2764. text="查看数据",
  2765. command=API.visual_learner,
  2766. font=FONT,
  2767. width=gui_width,
  2768. height=gui_height,
  2769. ).grid(
  2770. column=column + 1,
  2771. row=row,
  2772. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2773. )
  2774. tkinter.Button(
  2775. SCREEN,
  2776. bg=buttom_bg_color,
  2777. fg=word_color,
  2778. text="删除学习器",
  2779. command=API.del_learner,
  2780. font=FONT,
  2781. width=gui_width,
  2782. height=gui_height,
  2783. ).grid(
  2784. column=column + 2,
  2785. row=row,
  2786. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2787. )
  2788. row += 1
  2789. tkinter.Button(
  2790. SCREEN,
  2791. bg=buttom_bg_color,
  2792. fg=word_color,
  2793. text="训练机器",
  2794. command=API.fit_learner,
  2795. font=FONT,
  2796. width=gui_width,
  2797. height=gui_height,
  2798. ).grid(
  2799. column=column,
  2800. row=row,
  2801. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2802. )
  2803. tkinter.Button(
  2804. SCREEN,
  2805. bg=buttom_bg_color,
  2806. fg=word_color,
  2807. text="测试机器",
  2808. command=API.test_learner,
  2809. font=FONT,
  2810. width=gui_width,
  2811. height=gui_height,
  2812. ).grid(
  2813. column=column + 1,
  2814. row=row,
  2815. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2816. )
  2817. tkinter.Button(
  2818. SCREEN,
  2819. bg=buttom_bg_color,
  2820. fg=word_color,
  2821. text="数据预测",
  2822. command=API.predict_learner,
  2823. font=FONT,
  2824. width=gui_width,
  2825. height=gui_height,
  2826. ).grid(
  2827. column=column + 2,
  2828. row=row,
  2829. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2830. )
  2831. row += 1
  2832. tkinter.Label(
  2833. SCREEN,
  2834. text="【学习器选择和配置】",
  2835. bg=bg_color,
  2836. fg=word_color,
  2837. font=FONT,
  2838. width=gui_width * 3,
  2839. height=gui_height,
  2840. ).grid(
  2841. column=column,
  2842. columnspan=3,
  2843. row=row,
  2844. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2845. ) # 设置说明
  2846. row += 1
  2847. tkinter.Button(
  2848. SCREEN,
  2849. bg=buttom_bg_color,
  2850. fg=word_color,
  2851. text="线性回归",
  2852. command=API.add_generalized_linear,
  2853. font=FONT,
  2854. width=gui_width,
  2855. height=gui_height,
  2856. ).grid(
  2857. column=column,
  2858. row=row,
  2859. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2860. )
  2861. tkinter.Button(
  2862. SCREEN,
  2863. bg=buttom_bg_color,
  2864. fg=word_color,
  2865. text="岭回归",
  2866. command=API.add_ridge,
  2867. font=FONT,
  2868. width=gui_width,
  2869. height=gui_height,
  2870. ).grid(
  2871. column=column + 1,
  2872. row=row,
  2873. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2874. )
  2875. tkinter.Button(
  2876. SCREEN,
  2877. bg=buttom_bg_color,
  2878. fg=word_color,
  2879. text="Lasso",
  2880. command=API.add_lasso,
  2881. font=FONT,
  2882. width=gui_width,
  2883. height=gui_height,
  2884. ).grid(
  2885. column=column + 2,
  2886. row=row,
  2887. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2888. )
  2889. row += 1
  2890. tkinter.Button(
  2891. SCREEN,
  2892. bg=buttom_bg_color,
  2893. fg=word_color,
  2894. text="逻辑回归",
  2895. command=API.add_logistic_regression,
  2896. font=FONT,
  2897. width=gui_width,
  2898. height=gui_height,
  2899. ).grid(
  2900. column=column,
  2901. row=row,
  2902. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2903. )
  2904. tkinter.Button(
  2905. SCREEN,
  2906. bg=buttom_bg_color,
  2907. fg=word_color,
  2908. text="决策树",
  2909. command=API.show_sorry_gui,
  2910. font=FONT,
  2911. width=gui_width,
  2912. height=gui_height,
  2913. ).grid(
  2914. column=column + 1,
  2915. row=row,
  2916. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2917. )
  2918. tkinter.Button(
  2919. SCREEN,
  2920. bg=buttom_bg_color,
  2921. fg=word_color,
  2922. text="SVM",
  2923. command=API.show_sorry_gui,
  2924. font=FONT,
  2925. width=gui_width,
  2926. height=gui_height,
  2927. ).grid(
  2928. column=column + 2,
  2929. row=row,
  2930. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2931. )
  2932. row += 1
  2933. tkinter.Button(
  2934. SCREEN,
  2935. bg=buttom_bg_color,
  2936. fg=word_color,
  2937. text="朴素贝叶斯",
  2938. command=API.show_sorry_gui,
  2939. font=FONT,
  2940. width=gui_width,
  2941. height=gui_height,
  2942. ).grid(
  2943. column=column,
  2944. row=row,
  2945. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2946. )
  2947. tkinter.Button(
  2948. SCREEN,
  2949. bg=buttom_bg_color,
  2950. fg=word_color,
  2951. text="K邻近分类",
  2952. command=API.add_knn_regression,
  2953. font=FONT,
  2954. width=gui_width,
  2955. height=gui_height,
  2956. ).grid(
  2957. column=column + 1,
  2958. row=row,
  2959. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2960. )
  2961. tkinter.Button(
  2962. SCREEN,
  2963. bg=buttom_bg_color,
  2964. fg=word_color,
  2965. text="K邻近预测",
  2966. command=API.add_knn_class,
  2967. font=FONT,
  2968. width=gui_width,
  2969. height=gui_height,
  2970. ).grid(
  2971. column=column + 2,
  2972. row=row,
  2973. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2974. )
  2975. row += 1
  2976. learner_parameters = tkinter.Text(SCREEN, width=gui_width * 3, height=gui_height * 11)
  2977. learner_parameters.grid(
  2978. column=column,
  2979. row=row,
  2980. columnspan=3,
  2981. rowspan=11,
  2982. sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S,
  2983. )