def findbest(f, times): pos = tools.parseFEN(tools.FEN_INITIAL) searcher = sunfish.Searcher() print('Printing best move after seconds', times) print('-' * 60) totalpoints = 0 totaltests = 0 for line in f: fen, opts = tools.parseEPD(line, opt_dict=True) if type(opts) != dict or ('am' not in opts and 'bm' not in opts): print("Line didn't have am/bm in opts", line, opts) continue pos = tools.parseFEN(fen) # am -> avoid move; bm -> best move am = tools.parseSAN(pos, opts['am']) if 'am' in opts else None bm = tools.parseSAN(pos, opts['bm']) if 'bm' in opts else None print('Looking for am/bm', opts.get('am'), opts.get('bm')) points = 0 print(opts.get('id', 'unnamed'), end=' ', flush=True) for t in times: move, _, _ = tools.search(searcher, pos, t) mark = tools.renderSAN(pos, move) if am and move != am or bm and move == bm: mark += '(1)' points += 1 else: mark += '(0)' print(mark, end=' ', flush=True) totaltests += 1 print(points) totalpoints += points print('-' * 60) print('Total Points: %d/%d', totalpoints, totaltests)
def main(): args = sys.argv[1:] if len(args) < 5: return usage() dst_path = args[0] runNo_low = args[1] runNo_up = args[2] ecms = args[3] cms = args[4] sys.stdout.write('Scanning %s...\n' % dst_path) for runNo in range(int(runNo_low), int(runNo_up) + 1): dst_list = [] print '***************************************start to search***************************************' dst_list = search(dst_list, dst_path, '00' + str(runNo)) print '***************************************searching ending**************************************' if len(dst_list) > 0 and len(dst_list) < 20: write_file(ecms, cms, runNo, dst_list) elif len(dst_list) >= 20: dst_list_groups = group_files_by_num(dst_list, 20) i = 0 for dst_list_fill in dst_list_groups: write_file(ecms, cms, runNo, dst_list_fill, i) i += 1 else: print 'runNo: ' + str(runNo) + ' is empty, just ignore it!' print 'All done!'
def main(): args = sys.argv[1:] if len(args) < 7: return usage() dst_path = args[0] sample = args[1] decay = args[2] mode = args[3] type = args[4] ecms = args[5] dst_num = args[6] sys.stdout.write('Scanning %s...\n' % dst_path) dst_list = [] print '***************************************start to search***************************************' dst_list = search(dst_list, dst_path, '.dst') print '***************************************searching ending**************************************' dst_list_groups = group_files_by_num(dst_list, dst_num) i = 0 for dst_list_fill in dst_list_groups: file_name = sample + '_' + decay + '_' + mode + '_' + ecms + '_' + str( i) + '.txt' f = open(file_name, 'w') f.write('#include "$ROOTIOROOT/share/jobOptions_ReadRec.txt"\n') f.write('#include "$MAGNETICFIELDROOT/share/MagneticField.txt"\n') f.write('#include "$DTAGALGROOT/share/jobOptions_dTag.txt"\n') f.write('#include "$DDECAYALGROOT/share/jobOptions_DDecay.txt"\n') f.write('#include "$MEASUREDECMSSVCROOT/share/anaOptions.txt"\n') f.write('DDecay.Ecms = ' + str(float(ecms) / 1000.) + ';\n') f.write('DDecay.type = "' + type + '";\n') f.write('\n') f.write('// Input REC or DST file name\n') f.write('EventCnvSvc.digiRootInputFile = {\n') for dst in dst_list_fill: if dst != dst_list_fill[-1]: temp = '"' + dst + '",\n' f.write(temp) if dst == dst_list_fill[-1]: temp = '"' + dst + '"\n' f.write(temp) f.write('};\n') f.write('\n') f.write( '// Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL )\n' ) f.write('MessageSvc.OutputLevel = 6;\n') f.write('\n') f.write('// Number of events to be processed (default is 10)\n') f.write('ApplicationMgr.EvtMax = -1;\n') f.write('\n') f.write('ApplicationMgr.HistogramPersistency = "ROOT";\n') f.write( 'NTupleSvc.Output = {\"FILE1 DATAFILE=\'/besfs/groups/cal/dedx/$USER/bes/DstDpi/run/DstDpi/rootfile/' + sample + '/' + type + '/' + ecms + '/' + sample + '_' + decay + '_' + mode + '_' + ecms + '_' + str(i) + '.root' + '\' OPT=\'NEW\' TYP=\'ROOT\'\"};\n') f.close() i = i + 1 print 'All done!'
def test_3fold(self): sunfish.DRAW_TEST = True # Games where the last move is right, but the second to last move is wrong path_do = os.path.join(os.path.dirname(__file__), 'tests/3fold_do.pgn') # Games where the last move is wrong path_dont = os.path.join(os.path.dirname(__file__), 'tests/3fold_dont.pgn') with open(path_dont) as file: for i, (_pgn, pos_moves) in enumerate(tools.readPGN(file)): history = [] for pos, move in pos_moves: history.append(pos) last_pos, last_move = pos_moves[-1] # Maybe we just didn't like the position we were in. # This is a kind of crude way of testing that. if last_pos.score < 0: continue move, score, _ = tools.search(sunfish.Searcher(), pos, secs=.1, history=history[:-1]) if move == last_move: print('Score was', score, pos.score) print('Failed at', i) print(_pgn) self.assertNotEqual(move, last_move)
def test_selfplay(self): pos = tools.parseFEN(tools.FEN_INITIAL) for d in range(200): m, score, _ = tools.search(sunfish.Searcher(), pos, .1) if m is None: self.assertTrue(score == 0 or abs(score) >= sunfish.MATE_LOWER) break pos = pos.move(m)
def __click(self, destimg, refresh=True): if refresh: self.__refresh() pos = tools.search(self.__back, self.__imgs[destimg]) if len(pos) != 0: tools.touch(tools.cheat(pos)) #print("click "+destimg) return True return False
def allmate(path): with open(path) as f: for line in f: line = line.strip() print(line) pos = tools.parseFEN(line) _, score, _ = tools.search(sunfish.Searcher(), pos, secs=3600) if score < sunfish.MATE_LOWER: print("Unable to find mate. Only got score = %d" % score) break
def searchTemplets(): # 在鼠标焦点处插入输入内容 ''' 检索模板button相应事件 ''' query = t.get('0.0', 'end') res_list = tools.search(es, query) lb.delete(0, END) for res in res_list: res = res['_source'] lb.insert( 'end', '#' + res['title'].replace('.txt', '') + '#: ' + res['content'])
def selfplay(secs=1): """ Start a game amwafish vs. amwafish """ pos = tools.parseFEN(tools.FEN_INITIAL) for d in range(200): # Always print the board from the same direction board = pos.board if d % 2 == 0 else pos.rotate().board print(' '.join(board)) m, _, _ = tools.search(amwafish.Searcher(), pos, secs) if m is None: print("Game over") break print("\nmove", tools.mrender(pos, m)) pos = pos.move(m)
def get(self): query = self.rget('q') school = self.get_school_cookie() if not school: school = 'Bergen County Academies' results = search(school, query) if not results: self.render('search.html', {'query':query}) return guides = [r[0] for r in results] self.render('search.html', {'guides':guides, 'query':query})
def index(): statement = None weightOption = 1 InformationForm = IRForm(request.form) ret = [] if request.method == 'POST': if InformationForm.validate_on_submit(): statement = InformationForm.statement.data weightOption = InformationForm.scheme.data InformationForm.statement.data = '' tmp = 'Retrive results: \n' + search(DB_PATH, statement, weightOption) ret = tmp.split("\n") return render_template('index.html', form=InformationForm, statement=ret)
def main(): args = sys.argv[1:] if len(args) < 7: return usage() dst_path = args[0] sample = args[1] decay = args[2] mode = args[3] type = args[4] ecms = args[5] dst_num = args[6] sys.stdout.write('Scanning %s...\n' % dst_path) dst_list = [] print '***************************************start to search***************************************' dst_list = search(dst_list, dst_path, '.dst') print '***************************************searching ending**************************************' dst_list_groups = group_files_by_num(dst_list, dst_num) i = 0 for dst_list_fill in dst_list_groups: file_name = sample + '_' + decay + '_' + mode + '_' + ecms + '_' + str( i) + '.txt' f = open(file_name, 'w') f.write('#include "$ROOTIOROOT/share/jobOptions_ReadRec.txt"\n') f.write('#include "$MAGNETICFIELDROOT/share/MagneticField.txt"\n') f.write('#include "$DTAGALGROOT/share/jobOptions_dTag.txt"\n') f.write( '#include "$SIMPLEPIDSVCROOT/share/jobOptions_SimplePIDSvc.txt"\n') f.write('#include "$VERTEXFITROOT/share/jobOptions_VertexDbSvc.txt"\n') f.write('#include "$MEASUREDECMSSVCROOT/share/anaOptions.txt"\n') f.write('\n') f.write('NeutralDReconstruction.ReadBeamEFromDB = false;\n') f.write('NeutralDReconstruction.UseCalibBeamE = false;\n') f.write('NeutralDReconstruction.BeamE = 2.09;\n') f.write('NeutralDSelector.UseMbcCuts = false;\n') f.write('NeutralDSelector.UseDeltaECuts = false;\n') f.write('NeutralDSelector.UseDeltaMassCuts = true;\n') f.write('NeutralDSelector.DDeltaMassMinCut = -0.12;\n') f.write('NeutralDSelector.DDeltaMassMaxCut = 0.12;\n') f.write('ChargedDReconstruction.ReadBeamEFromDB = false;\n') f.write('ChargedDReconstruction.UseCalibBeamE = false;\n') f.write('ChargedDSelector.UseMbcCuts = false;\n') f.write('ChargedDSelector.UseDeltaECuts = false;\n') f.write('ChargedDSelector.UseDeltaMassCuts = true;\n') f.write('ChargedDSelector.DDeltaMassMinCut = -0.12;\n') f.write('ChargedDSelector.DDeltaMassMaxCut = 0.12;\n') f.write('LocalKaonSelector.useSimplePID = false;\n') f.write('LocalPionSelector.useSimplePID = false;\n') f.write('\n') f.write('ApplicationMgr.DLLs += {"PiD0DmAlg"};\n') f.write('ApplicationMgr.TopAlg +={ "PiD0Dm" };\n') f.write('PiD0Dm.AddModesD0 = {0, 1, 3, 4};\n') f.write('PiD0Dm.AddModesDm = {200, 201, 202, 203, 204};\n') f.write('PiD0Dm.sample_types = {"signal"};\n') f.write('PiD0Dm.Ecms = ' + str(float(ecms) / 1000.) + ';\n') f.write('PiD0Dm.W_D0 = 0.024;\n') f.write('PiD0Dm.W_Dm = 0.020;\n') f.write('\n') f.write('// Input REC or DST file name\n') f.write('EventCnvSvc.digiRootInputFile = {\n') for dst in dst_list_fill: if dst != dst_list_fill[-1]: temp = '"' + dst + '",\n' f.write(temp) if dst == dst_list_fill[-1]: temp = '"' + dst + '"\n' f.write(temp) f.write('};\n') f.write('\n') f.write( '// Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL )\n' ) f.write('MessageSvc.OutputLevel = 6;\n') f.write('\n') f.write('// Number of events to be processed (default is 10)\n') f.write('ApplicationMgr.EvtMax = -1;\n') f.write('\n') f.write('ApplicationMgr.HistogramPersistency = "ROOT";\n') f.write( 'NTupleSvc.Output = {\"FILE1 DATAFILE=\'/besfs/groups/cal/dedx/$USER/bes/DDbarPi-DT/run/DDbarPi/rootfile/' + sample + '/' + type + '/' + ecms + '/' + sample + '_' + decay + '_' + mode + '_' + ecms + '_' + str(i) + '.root' + '\' OPT=\'NEW\' TYP=\'ROOT\'\"};\n') f.close() i = i + 1 print 'All done!'
def __contains(self, destimg, refresh=True): if refresh: self.__refresh() if len(tools.search(self.__back, self.__imgs[destimg])) == 0: return False return True
def main(): args = sys.argv[1:] if len(args) < 8: return usage() dst_path = args[0] sample = args[1] decay = args[2] mode = args[3] type = args[4] ecms = args[5] cms = args[6] dst_num = args[7] sys.stdout.write('Scanning %s...\n' % dst_path) dst_list = [] print '***************************************start to search***************************************' dst_list = search(dst_list, dst_path, '.dst') print '***************************************searching ending**************************************' dst_list_groups = group_files_by_num(dst_list, dst_num) i = 0 for dst_list_fill in dst_list_groups: file_name = sample + '_' + decay + '_' + mode + '_' + ecms + '_' + str( i) + '.txt' f = open(file_name, 'w') f.write('#include "$ROOTIOROOT/share/jobOptions_ReadRec.txt"\n') f.write('#include "$MAGNETICFIELDROOT/share/MagneticField.txt"\n') f.write('#include "$DTAGALGROOT/share/jobOptions_dTag.txt"\n') f.write('#include "$DDECAYALGROOT/share/jobOptions_DDecay.txt"\n') f.write('#include "$MEASUREDECMSSVCROOT/share/anaOptions.txt"\n') f.write('DDecay.IsMonteCarlo = true;\n') f.write('DDecay.Ecms = ' + str(float(cms) / 1000.) + ';\n') f.write('DDecay.W_m_Kpipi = ' + str(width(ecms[0:4])) + ';\n') f.write('DDecay.W_rm_Dpipi = ' + str(window(ecms[0:4])) + ';\n') f.write('\n') f.write('DTag.NeutralDReconstruction = true;\n') f.write('DTag.ChargedDReconstruction = true;\n') f.write('DTag.DsReconstruction = true;\n') f.write('\n') f.write('NeutralDSelector.UseMbcCuts = false;\n') f.write('eutralDSelector.UseDeltaECuts = false;\n') f.write('NeutralDSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('ChargedDSelector.UseMbcCuts = false;\n') f.write('ChargedDSelector.UseDeltaECuts = false;\n') f.write('ChargedDSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('DsSelector.UseMbcCuts = false;\n') f.write('DsSelector.UseDeltaECuts = false;\n') f.write('DsSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('// Input REC or DST file name\n') f.write('EventCnvSvc.digiRootInputFile = {\n') for dst in dst_list_fill: if dst != dst_list_fill[-1]: temp = '"' + dst + '",\n' f.write(temp) if dst == dst_list_fill[-1]: temp = '"' + dst + '"\n' f.write(temp) f.write('};\n') f.write('\n') f.write( '// Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL )\n' ) f.write('MessageSvc.OutputLevel =6;\n') f.write('\n') f.write('// Number of events to be processed (default is 10)\n') f.write('ApplicationMgr.EvtMax = -1;\n') f.write('\n') f.write('ApplicationMgr.HistogramPersistency = "ROOT";\n') f.write( 'NTupleSvc.Output = {\"FILE1 DATAFILE=\'/scratchfs/bes/$USER/bes/DDPIPI/v0.2/' + sample + '/' + type + '/' + ecms + '/sys_err/psipp_shape/rootfile/' + sample + '_' + decay + '_' + mode + '_' + ecms + '_' + str(i) + '.root' + '\' OPT=\'NEW\' TYP=\'ROOT\'\"};\n') f.close() i = i + 1 print 'All done!'
def play(version1_version2_secs_plus_fen): ''' returns 1 if fish1 won, 0 for draw and -1 otherwise ''' version1, version2, secs, plus, fen = version1_version2_secs_plus_fen modules = [importlib.import_module(version1), importlib.import_module(version2)] searchers = [] for module in modules: if hasattr(module, 'Searcher'): searchers.append(module.Searcher()) else: searchers.append(module) times = [secs, secs] efactor = [1, 1] pos = tools.parseFEN(fen) seen = set() for d in range(200): moves_remain = 30 use = times[d%2]/moves_remain + plus # Use a bit more time, if we have more on the clock than our opponent use += (times[d%2] - times[(d+1)%2])/10 use = max(use, plus) t = time.time() m, score, depth = tools.search(searchers[d%2], pos, use*efactor[d%2]) efactor[d%2] *= (use/(time.time() - t))**.5 times[d%2] -= time.time() - t times[d%2] += plus #print('Used {:.2} rather than {:.2}. Off by {:.2}. Remaining: {}' #.format(time.time()-t, use, (time.time()-t)/use, times[d%2])) if times[d%2] < 0: print('{} ran out of time'.format(version2 if d%2 == 1 else version1)) return version1 if d%2 == 1 else version2 pass if m is None: print('Game not done, but no move? Score', score) name = version1 if d%2 == 0 else version2 print(version1, tools.renderFEN(pos)) assert False # Test move is_dead = lambda pos: any(pos.value(m) >= amwafish.MATE_LOWER for m in pos.gen_moves()) if is_dead(pos.move(m)): name = version1 if d%2 == 0 else version2 print('{} made an illegal move {} in position {}. Depth {}, Score {}'. format(name, tools.mrender(pos,m), tools.renderFEN(pos), depth, score)) return version2 if d%2 == 0 else version1 #assert False # Make the move pos = pos.move(m) # Test repetition draws # This is by far the most common type of draw if pos in seen: #print('Rep time at end', times) return None seen.add(pos) any_moves = not all(is_dead(pos.move(m)) for m in pos.gen_moves()) in_check = is_dead(pos.nullmove()) if not any_moves: if not in_check: # This is actually a bit interesting. Why would we ever throw away a win like this? name = version1 if d%2 == 0 else version2 print('{} stalemated? depth {} {}'.format( name, depth, tools.renderFEN(pos))) if score != 0: print('it got the wrong score: {} != 0'.format(score)) return None else: name = version1 if d%2 == 0 else version2 if score < amwafish.MATE_LOWER: print('{} mated, but did not realize. Only scored {} in position {}, depth {}'.format(name, score, tools.renderFEN(pos), depth)) return name print('Game too long', tools.renderFEN(pos)) return None
def main(): args = sys.argv[1:] if len(args) < 3: return usage() dst_path = args[0] runNo_low = args[1] runNo_up = args[2] energy = args[3] sys.stdout.write('Scanning %s...\n' % dst_path) for runNo in range(int(runNo_low), int(runNo_up) + 1): dst_list = [] print '***************************************start to search***************************************' dst_list = search(dst_list, dst_path, '00' + str(runNo)) print '***************************************searching ending**************************************' if dst_list: file_name = 'data' + str(runNo) + '.txt' f = open(file_name, 'w') f.write('#include "$ROOTIOROOT/share/jobOptions_ReadRec.txt"\n') f.write('#include "$MAGNETICFIELDROOT/share/MagneticField.txt"\n') f.write('#include "$DTAGALGROOT/share/jobOptions_dTag.txt"\n') f.write('#include "$DDECAYALGROOT/share/jobOptions_DDecay.txt"\n') f.write('\n') f.write('DTag.NeutralDReconstruction = true;\n') f.write('DTag.ChargedDReconstruction = true;\n') f.write('DTag.DsReconstruction = true;\n') f.write('\n') f.write('NeutralDSelector.UseMbcCuts = false;\n') f.write('eutralDSelector.UseDeltaECuts = false;\n') f.write('NeutralDSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('ChargedDSelector.UseMbcCuts = false;\n') f.write('ChargedDSelector.UseDeltaECuts = false;\n') f.write('ChargedDSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('DsSelector.UseMbcCuts = false;\n') f.write('DsSelector.UseDeltaECuts = false;\n') f.write('DsSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('// Input REC or DST file name\n') f.write('EventCnvSvc.digiRootInputFile = {\n') print 'processing runNo: ' + str(runNo) + ' with ' + str( len(dst_list)) + ' dst files...' for dst in dst_list: if dst != dst_list[-1]: temp = '"' + dst + '",\n' f.write(temp) if dst == dst_list[-1]: temp = '"' + dst + '"\n' f.write(temp) f.write('};\n') f.write('\n') f.write( '// Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL )\n' ) f.write('MessageSvc.OutputLevel =6;\n') f.write('\n') f.write('// Number of events to be processed (default is 10)\n') f.write('ApplicationMgr.EvtMax = -1;\n') f.write('\n') f.write('ApplicationMgr.HistogramPersistency = "ROOT";\n') f.write( 'NTupleSvc.Output = {\"FILE1 DATAFILE=\'/scratchfs/bes/$USER/bes/DDPIPI/v0.2/data/' + energy + '/' + 'data' + str(runNo) + '.root\' OPT=\'NEW\' TYP=\'ROOT\'\"};\n') f.close() else: print 'runNo: ' + str(runNo) + ' is empty, just ignore it!' print 'All done!'
def initGUI(): global item_list es = Elasticsearch() # =============== 初始化窗口 =============== window = tk.Tk() window.title('Report demo') window.geometry('1000x700') # 这里的乘是小x w * h # =============== frame设置 =============== fr_top = tk.Frame(window, height=20, width=1000) fr_top.pack() fr_left = tk.Frame(window) fr_left.pack(side='left') fr_right = tk.Frame(window) fr_right.pack(side='right') fr_lt = tk.Frame(fr_left) fr_lt.pack(side='top') fr_lb = tk.Frame(fr_left) fr_lb.pack(side='bottom') fr_rt = tk.Frame(fr_right) fr_rt.pack(side='top') fr_rb = tk.Frame(fr_right) fr_rb.pack(side='bottom') # =============== label =============== lab1 = tk.Label(fr_top, text='检验报告单', font=('Arial', 25), height=2) lab1.pack(side='top') lab2 = tk.Label(fr_rt, text='模板库', font=('Arial', 15), height=2) lab2.pack(side='top') lab3 = tk.Label(fr_lt, text='诊断及意见', font=('Arial', 15), height=2) lab3.pack(side='top') # lab4 = tk.Label(fr_top, text='', font=('Arial', 15), height = 2) # lab4.pack(side = 'bottom') # =============== 表格设置 =============== columns = ('序号', '项目', '结果') treeview = ttk.Treeview(fr_top, height=14, show="headings", columns=columns) # 表格 treeview.column("序号", width=100, anchor='center') treeview.column("项目", width=500, anchor='center') # 表示列,不显示 treeview.column("结果", width=500, anchor='center') treeview.heading("序号", text="序号") treeview.heading("项目", text="项目") # 显示表头 treeview.heading("结果", text="结果") treeview.pack(fill=BOTH) def writeTable(): # 清空表格 x = treeview.get_children() for item in x: treeview.delete(item) # 填入表格 createTable() for index, item in enumerate(item_list): # 写入数据 treeview.insert('', index, values=(str(index + 1), item['name'], item['value'])) writeTable() print(item_list) # =============== Listbox设置=============== lb = tk.Listbox(fr_rt, width=40, height=10, relief='raised', fg="blue", bd=2) lb.pack() res_list = tools.search(es, '模板') lb.delete(0, END) for res in res_list: res = res['_source'] lb.insert( 'end', '#' + res['title'].replace('.txt', '') + '#: ' + res['content']) # =============== text控件 =============== t = tk.Text(fr_lt, height=15, width=100, relief='raised', bd=2) t.pack() # =============== button =============== def searchTemplets(): # 在鼠标焦点处插入输入内容 ''' 检索模板button相应事件 ''' query = t.get('0.0', 'end') res_list = tools.search(es, query) lb.delete(0, END) for res in res_list: res = res['_source'] lb.insert( 'end', '#' + res['title'].replace('.txt', '') + '#: ' + res['content']) b1 = tk.Button(fr_lb, text='检索模板', width=10, height=2, command=searchTemplets) b1.pack(side='left') def addText(): ''' 获取text框中的文本,方便进行检索 ''' text = t.get('0.0', 'end') info_dict = tools.extract(text, item_list) # 抽取信息 t.delete('0.0', 'end') text = lb.get(lb.curselection()) text = re.sub(re.compile(r'#.*#: '), '', text) text = tools.fullfill(text, info_dict) # 自动填充文本 text = re.sub(re.compile(r'<e>.*<e>'), '__', text) # text = text.replace('<e>.*<e>', '____') t.insert('end', text) # 获取当前选中的文本 b2 = tk.Button(fr_rb, text='应用模板', width=10, height=2, command=addText) b2.pack() def saveReport(): ''' 保存当前报告,并且刷新表格信息 ''' writeFile(REPORT_PATH, item_list, t.get('0.0', 'end')) t.delete('0.0', 'end') # 刷新text框 writeTable() # 刷新表格 b3 = tk.Button(fr_lb, text='保存', width=10, height=2, command=saveReport) b3.pack(side='right') window.mainloop()