该项目是应贾德文要求,做一个后端数值计算+前端GUI实现,要求开发工具兼具较强的数值计算能力(尤其是矩阵和向量计算)、易用性(不需要内存、指针、堆栈、消息等专门知识)、用户图形界面(GUI)开发和程序打包(生成单一exe文件)功能。备选方案有pyhton、matlab和scilab,matlab是商业软件,体积庞大,GUI和打包比较麻烦,scilab数值计算功能一般,语法比较独特,GUI采用Tcl实现,好像也没有打包功能,而python平台在这方面表现最好,numpy模块的数值计算功能强大,GUI设计方面,简单界面可选Tkinter,复杂的可选wxPython,打包用py2exe模块,因此本项目最终选择在WinXP + python2.5平台上完成。 tkinter的界面设计基本方法:多层frame嵌套; 一般是两句定义一个控件,第一句定义控件特征,第二句定义放置方法,Label和Button可实现单语句定义; 向量数字的格式化输出,同时转化为长度固定的字符串: Python中[for ii in aa]的强大功能:见附件的第212、213行(给resMtx幅值的语句,在表达式中使用for语句); Text的tab控制输出格式:格式字符串也可实现对齐,但tab stop有4种对齐方式,功能更强; GUI字体的设置方法:定义专门的字体设置字符串; 中文GUI界面的编码问题:在文件头加上:# -- coding:utf-8 --,指明用utf8编码; CheckBox的判断: 界面上取得的字符串转化为数组,进行数学运算后表现在界面上: from numpy import * from Tkinter import * def solve1(): resStr = inp_txt.get('1.0',END) bb = fromstring(resStr,'d',-1,' ').reshape(3,-1) print type(bb) print bb.shape out_txt.insert('1.0', transpose(bb)) root = Tk() top = Frame(root) top.pack(side='top') inp_txt = Text(top, font=('Times',12),height=5,width=30) inp_txt.insert('1.0','12 23\n34 45\n34.5 98.234') inp_txt.pack(side='top') Button(top, text='solve', command=solve1).pack(side='top',padx=40) out_txt = Text(top, font=('Times',12),height=5,width=30) out_txt.pack(side='top') root.mainloop() 其他python编程实践:单句代码的折行、多句代码放在一行;pass语句的作用;
下面是Anova.py文件内容: # -- coding:utf-8 -- from Tkinter import Tk, Frame, LabelFrame, Label, Entry, Text, Button, \ IntVar, Checkbutton, X, CENTER, NUMERIC, END from numpy import zeros, transpose, fromstring, reshape import rwMtx as rwm from tkMessageBox import showwarning
def Anova7(schMtx, calcMtx): k = 7 # total number of factors m = 3 # total number of levels n = 18 # total number of experiments r = n/m # here add the format check T = sum(calcMtx) CT = T2/n QT = sum(calcMtx2) ST = QT - CT K = zeros((m ,k)) K[0,0] = sum(calcMtx[0:3]) + sum(calcMtx[9:12]) K[1,0] = sum(calcMtx[3:6]) + sum(calcMtx[12:15]) K[2,0] = sum(calcMtx[6:9]) + sum(calcMtx[15:18]) K[0,1] = calcMtx[0]+calcMtx[3]+calcMtx[6]+calcMtx[9]+calcMtx[12]+calcMtx[15] K[1,1] = calcMtx[1]+calcMtx[4]+calcMtx[7]+calcMtx[10]+calcMtx[13]+calcMtx[16] K[2,1] = calcMtx[2]+calcMtx[5]+calcMtx[8]+calcMtx[11]+calcMtx[14]+calcMtx[17] K[0,2] = calcMtx[0]+calcMtx[3]+calcMtx[8]+calcMtx[10]+calcMtx[14]+calcMtx[16] K[1,2] = calcMtx[1]+calcMtx[4]+calcMtx[6]+calcMtx[11]+calcMtx[12]+calcMtx[17] K[2,2] = calcMtx[2]+calcMtx[5]+calcMtx[7]+calcMtx[9]+calcMtx[13]+calcMtx[15] K[0,3] = calcMtx[0]+calcMtx[5]+calcMtx[6]+calcMtx[10]+calcMtx[13]+calcMtx[17] K[1,3] = calcMtx[1]+calcMtx[3]+calcMtx[7]+calcMtx[11]+calcMtx[14]+calcMtx[15] K[2,3] = calcMtx[2]+calcMtx[4]+calcMtx[8]+calcMtx[9]+calcMtx[12]+calcMtx[16] K[0,4] = calcMtx[0]+calcMtx[5]+calcMtx[7]+calcMtx[11]+calcMtx[12]+calcMtx[16] K[1,4] = calcMtx[1]+calcMtx[3]+calcMtx[8]+calcMtx[9]+calcMtx[13]+calcMtx[17] K[2,4] = calcMtx[2]+calcMtx[4]+calcMtx[6]+calcMtx[10]+calcMtx[14]+calcMtx[15] K[0,5] = calcMtx[0]+calcMtx[4]+calcMtx[8]+calcMtx[11]+calcMtx[13]+calcMtx[15] K[1,5] = calcMtx[1]+calcMtx[5]+calcMtx[6]+calcMtx[9]+calcMtx[14]+calcMtx[16] K[2,5] = calcMtx[2]+calcMtx[3]+calcMtx[7]+calcMtx[10]+calcMtx[12]+calcMtx[17] K[0,6] = calcMtx[0]+calcMtx[4]+calcMtx[7]+calcMtx[9]+calcMtx[14]+calcMtx[17] K[1,6] = calcMtx[1]+calcMtx[5]+calcMtx[8]+calcMtx[10]+calcMtx[12]+calcMtx[15] K[2,6] = calcMtx[2]+calcMtx[3]+calcMtx[6]+calcMtx[11]+calcMtx[13]+calcMtx[16] Q = zeros(k) for i in range(k): Q[i] = sum(K[:,i]**2)/r S = Q - CT Se = ST - sum(S) # error of S dofLevel = m - 1 # degree of freedom dofSum = n - 1 dofErr = dofSum - dofLevel * k sms = S / dofLevel # sum of mean square errSms = Se / dofErr F0 = sms / errSms Ap = (F0 - F0.min())/((F0.max() - F0.min())/0.9) + 0.1 A = (Ap/sum(Ap)).transpose() R = zeros((k,m)) for i in range(k): R[i,:] = (schMtx[i,:] - schMtx[i,:].min())/((schMtx[i,:].max() - schMtx[i,:].min())/0.9) + 0.1 B = zeros(m) for i in range(m): dd = zeros(k) for j in range(k): dd[j] = min(A[j],R[j,i]) B[i] = max(dd) min_index = B.argmin() # optimization result # assemble the return value: return B, schMtx[:,min_index]
def Anova5(calcMtx): k = 5 # total number of factors m = 3 # total number of levels n = 18 # total number of experiments r = n/m # here add the format check T = sum(calcMtx) CT = T2/n QT = sum(calcMtx2) ST = QT - CT K = zeros((m ,k)) K[0,0] = sum(calcMtx[0:3]) + sum(calcMtx[9:12]) K[1,0] = sum(calcMtx[3:6]) + sum(calcMtx[12:15]) K[2,0] = sum(calcMtx[6:9]) + sum(calcMtx[15:18]) K[0,1] = calcMtx[0]+calcMtx[3]+calcMtx[6]+calcMtx[9]+calcMtx[12]+calcMtx[15] K[1,1] = calcMtx[1]+calcMtx[4]+calcMtx[7]+calcMtx[10]+calcMtx[13]+calcMtx[16] K[2,1] = calcMtx[2]+calcMtx[5]+calcMtx[8]+calcMtx[11]+calcMtx[14]+calcMtx[17] K[0,2] = calcMtx[0]+calcMtx[3]+calcMtx[8]+calcMtx[10]+calcMtx[14]+calcMtx[16] K[1,2] = calcMtx[1]+calcMtx[4]+calcMtx[6]+calcMtx[11]+calcMtx[12]+calcMtx[17] K[2,2] = calcMtx[2]+calcMtx[5]+calcMtx[7]+calcMtx[9]+calcMtx[13]+calcMtx[15] K[0,3] = calcMtx[0]+calcMtx[5]+calcMtx[7]+calcMtx[11]+calcMtx[12]+calcMtx[16] K[1,3] = calcMtx[1]+calcMtx[3]+calcMtx[8]+calcMtx[9]+calcMtx[13]+calcMtx[17] K[2,3] = calcMtx[2]+calcMtx[4]+calcMtx[6]+calcMtx[10]+calcMtx[14]+calcMtx[15] K[0,4] = calcMtx[0]+calcMtx[4]+calcMtx[8]+calcMtx[11]+calcMtx[13]+calcMtx[15] K[1,4] = calcMtx[1]+calcMtx[5]+calcMtx[6]+calcMtx[9]+calcMtx[14]+calcMtx[16] K[2,4] = calcMtx[2]+calcMtx[3]+calcMtx[7]+calcMtx[10]+calcMtx[12]+calcMtx[17] Q = zeros(k) for i in range(k): Q[i] = sum(K[:,i]**2)/r S = Q - CT Se = ST - sum(S) # error of S dofLevel = m - 1 # degree of freedom dofSum = n - 1 dofErr = dofSum - dofLevel * k sms = S / dofLevel # sum of mean square errSms = Se / dofErr F0 = sms / errSms optLevel = K.argmin(0)+1 resMtx = {'factors':['A', 'B', 'C', 'D', 'E', 'Error', 'Sum'], 'S':['%10.5f'%ii for ii in S], 'Se':'%10.5f'%Se, 'ST':'%10.5f'%ST,\ 'dofLevel':dofLevel, 'dofErr':dofErr, 'dofSum':dofSum, 'sms':['%10.5f'%ii for ii in sms], 'errSms':'%10.5f'%errSms, 'F0':['%10.5f'%ii for ii in F0], 'optLevel':optLevel} return resMtx
def Anova4(calcMtx): k = 4 # total number of factors m = 3 # total number of levels n = 9 # total number of experiments r = n/m # here add the format check T = sum(calcMtx) CT = T2/n QT = sum(calcMtx2) ST = QT - CT K = zeros((m ,k)) K[0,0] = calcMtx[0]+calcMtx[1]+calcMtx[2] K[1,0] = calcMtx[3]+calcMtx[4]+calcMtx[5] K[2,0] = calcMtx[6]+calcMtx[7]+calcMtx[8] K[0,1] = calcMtx[0]+calcMtx[3]+calcMtx[6] K[1,1] = calcMtx[1]+calcMtx[4]+calcMtx[7] K[2,1] = calcMtx[2]+calcMtx[5]+calcMtx[8] K[0,2] = calcMtx[0]+calcMtx[5]+calcMtx[7] K[1,2] = calcMtx[1]+calcMtx[3]+calcMtx[8] K[2,2] = calcMtx[2]+calcMtx[4]+calcMtx[6] K[0,3] = calcMtx[0]+calcMtx[4]+calcMtx[8] K[1,3] = calcMtx[1]+calcMtx[5]+calcMtx[6] K[2,3] = calcMtx[2]+calcMtx[3]+calcMtx[7] Q = zeros(k) for i in range(k): Q[i] = sum(K[:,i]**2)/r S = Q - CT Se = min(S) # error of S dofLevel = m - 1 # degree of freedom dofSum = n - 1 dofErr = dofLevel sms = S / dofLevel # sum of mean square errSms = Se / dofErr F0 = sms / errSms optLevel = K.argmin(0)+1 resMtx = {'factors':['A', 'B', 'C', 'D', 'Error', 'Sum'], 'S':['%10.5f'%ii for ii in S], 'Se':'%10.5f'%Se, 'ST':'%10.5f'%ST,\ 'dofLevel':dofLevel, 'dofErr':dofErr, 'dofSum':dofSum, 'sms':['%10.5f'%ii for ii in sms], 'errSms':'%10.5f'%errSms, 'F0':['%10.5f'%ii for ii in F0], 'optLevel':optLevel} return resMtx
def Anova3(calcMtx): k = 3 # total number of factors m = 3 # total number of levels n = 9 # total number of experiments r = n/m # here add the format check T = sum(calcMtx) CT = T2/n QT = sum(calcMtx2) ST = QT - CT K = zeros((m ,k)) K[0,0] = calcMtx[0]+calcMtx[1]+calcMtx[2] K[1,0] = calcMtx[3]+calcMtx[4]+calcMtx[5] K[2,0] = calcMtx[6]+calcMtx[7]+calcMtx[8] K[0,1] = calcMtx[0]+calcMtx[3]+calcMtx[6] K[1,1] = calcMtx[1]+calcMtx[4]+calcMtx[7] K[2,1] = calcMtx[2]+calcMtx[5]+calcMtx[8] K[0,2] = calcMtx[0]+calcMtx[5]+calcMtx[7] K[1,2] = calcMtx[1]+calcMtx[3]+calcMtx[8] K[2,2] = calcMtx[2]+calcMtx[4]+calcMtx[6] Q = zeros(k) for i in range(k): Q[i] = sum(K[:,i]**2)/r S = Q - CT Se = ST - sum(S) # error of S dofLevel = m - 1 # degree of freedom dofSum = n - 1 dofErr = dofSum - dofLevel * k sms = S / dofLevel # sum of mean square errSms = Se / dofErr F0 = sms / errSms optLevel = K.argmin(0)+1 resMtx = {'factors':['A', 'B', 'C', 'Error', 'Sum'], 'S':['%10.5f'%ii for ii in S], 'Se':'%10.5f'%Se, 'ST':'%10.5f'%ST,\ 'dofLevel':dofLevel, 'dofErr':dofErr, 'dofSum':dofSum, 'sms':['%10.5f'%ii for ii in sms], 'errSms':'%10.5f'%errSms, 'F0':['%10.5f'%ii for ii in F0], 'optLevel':optLevel} return resMtx
def Anova2(calcMtx): k = 2 # total number of factors m = 3 # total number of levels n = 9 # total number of experiments r = n/m # here add the format check T = sum(calcMtx) CT = T2/n QT = sum(calcMtx2) ST = QT - CT K = zeros((m ,k)) K[0,0] = calcMtx[0]+calcMtx[1]+calcMtx[2] K[1,0] = calcMtx[3]+calcMtx[4]+calcMtx[5] K[2,0] = calcMtx[6]+calcMtx[7]+calcMtx[8] K[0,1] = calcMtx[0]+calcMtx[3]+calcMtx[6] K[1,1] = calcMtx[1]+calcMtx[4]+calcMtx[7] K[2,1] = calcMtx[2]+calcMtx[5]+calcMtx[8] Q = zeros(k) for i in range(k): Q[i] = sum(K[:,i]**2)/r S = Q - CT Se = ST - sum(S) # error of S dofLevel = m - 1 # degree of freedom dofSum = n - 1 dofErr = dofSum - dofLevel * k sms = S / dofLevel # sum of mean square errSms = Se / dofErr F0 = sms / errSms optLevel = K.argmin(0)+1 resMtx = {'factors':['A', 'B', 'Error', 'Sum'], 'S':['%10.5f'%ii for ii in S], 'Se':'%10.5f'%Se, 'ST':'%10.5f'%ST,\ 'dofLevel':dofLevel, 'dofErr':dofErr, 'dofSum':dofSum, 'sms':['%10.5f'%ii for ii in sms], 'errSms':'%10.5f'%errSms, 'F0':['%10.5f'%ii for ii in F0], 'optLevel':optLevel} return resMtx
def F0_evaluate(input_array, factor_number): #F0数组显著性判断函数 #print input_array if factor_number==5: F_005 = 4.74 F_001 = 9.55 elif factor_number==2: F_005 = 6.94 F_001 = 18 else: F_005 = 19 F_001 = 99 eval_res = [] for theValue in input_array: theNumber = float(theValue) if theNumber>F_001: eval_res.append('*') elif theNumber<F_005: eval_res.append('-') else: eval_res.append('') return eval_res
def solve_7(): tStr = txt_sch.get('1.0',END) schemeMtx = transpose(fromstring(tStr,'d',-1,' ').reshape(3,-1)) tStr = txt_expRes.get('1.0',END) calcResMtx = fromstring(tStr,'d',-1,' ') txt_optRes.delete(0, END) txt_optRes.insert(0, Anova7(schemeMtx, calcResMtx)[0]) txt_optSch.delete(0, END) txt_optSch.insert(0, Anova7(schemeMtx, calcResMtx)[1])
def solve_2345(): selected_item = chkb1.get()+chkb2.get()+chkb3.get()+chkb4.get()+chkb5.get() if selected_item == 5: calcResFile = open('data/expRes5.txt','r') calcResMtx = rwm.read(calcResFile) calcResFile.close() theRes = Anova5(calcResMtx) tt = '\t'+theRes['factors'][0]+'\t'+theRes['S'][0]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][0]+'\t'+theRes['F0'][0]+'\t'+F0_evaluate(theRes['F0'],5)[0]+'\n' \ +'\t'+theRes['factors'][1]+'\t'+theRes['S'][1]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][1]+'\t'+theRes['F0'][1]+'\t'+F0_evaluate(theRes['F0'],5)[1]+'\n' \ +'\t'+theRes['factors'][2]+'\t'+theRes['S'][2]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][2]+'\t'+theRes['F0'][2]+'\t'+F0_evaluate(theRes['F0'],5)[2]+'\n' \ +'\t'+theRes['factors'][3]+'\t'+theRes['S'][3]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][3]+'\t'+theRes['F0'][3]+'\t'+F0_evaluate(theRes['F0'],5)[3]+'\n' \ +'\t'+theRes['factors'][4]+'\t'+theRes['S'][4]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][4]+'\t'+theRes['F0'][4]+'\t'+F0_evaluate(theRes['F0'],5)[4]+'\n' \ +'\t'+theRes['factors'][5]+'\t'+theRes['Se']+'\t'+str(theRes['dofErr'])+'\t' +theRes['errSms']+'\n' \ +'\t'+theRes['factors'][6]+'\t'+theRes['ST']+'\t'+str(theRes['dofSum']) f3_res.delete('1.0', END) f3_res.insert('1.0', tt) txt_optLevel.delete(0, END) txt_optLevel.insert(0, theRes['optLevel']) elif selected_item == 4: calcResFile = open('data/expRes4.txt','r') calcResMtx = rwm.read(calcResFile) calcResFile.close() theRes = Anova4(calcResMtx) tt = '\t'+theRes['factors'][0]+'\t'+theRes['S'][0]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][0]+'\t'+theRes['F0'][0]+'\t'+F0_evaluate(theRes['F0'],4)[0]+'\n' \ +'\t'+theRes['factors'][1]+'\t'+theRes['S'][1]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][1]+'\t'+theRes['F0'][1]+'\t'+F0_evaluate(theRes['F0'],4)[1]+'\n' \ +'\t'+theRes['factors'][2]+'\t'+theRes['S'][2]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][2]+'\t'+theRes['F0'][2]+'\t'+F0_evaluate(theRes['F0'],4)[2]+'\n' \ +'\t'+theRes['factors'][3]+'\t'+theRes['S'][3]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][3]+'\t'+theRes['F0'][3]+'\t'+F0_evaluate(theRes['F0'],4)[3]+'\n' \ +'\t'+theRes['factors'][4]+'\t'+theRes['Se']+'\t'+str(theRes['dofErr'])+'\t' +theRes['errSms']+'\n' \ +'\t'+theRes['factors'][5]+'\t'+theRes['ST']+'\t'+str(theRes['dofSum']) f3_res.delete('1.0', END) f3_res.insert('1.0', tt) txt_optLevel.delete(0, END) txt_optLevel.insert(0, theRes['optLevel']) elif selected_item == 3: calcResFile = open('data/expRes3.txt','r') calcResMtx = rwm.read(calcResFile) calcResFile.close() theRes = Anova3(calcResMtx) tt = '\t'+theRes['factors'][0]+'\t'+theRes['S'][0]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][0]+'\t'+theRes['F0'][0]+'\t'+F0_evaluate(theRes['F0'],3)[0]+'\n' \ +'\t'+theRes['factors'][1]+'\t'+theRes['S'][1]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][1]+'\t'+theRes['F0'][1]+'\t'+F0_evaluate(theRes['F0'],3)[1]+'\n' \ +'\t'+theRes['factors'][2]+'\t'+theRes['S'][2]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][2]+'\t'+theRes['F0'][2]+'\t'+F0_evaluate(theRes['F0'],3)[2]+'\n' \ +'\t'+theRes['factors'][3]+'\t'+theRes['Se']+'\t'+str(theRes['dofErr'])+'\t' +theRes['errSms']+'\n' \ +'\t'+theRes['factors'][4]+'\t'+theRes['ST']+'\t'+str(theRes['dofSum']) f3_res.delete('1.0', END) f3_res.insert('1.0', tt) txt_optLevel.delete(0, END) txt_optLevel.insert(0, theRes['optLevel']) elif selected_item == 2: calcResFile = open('data/expRes2.txt','r') calcResMtx = rwm.read(calcResFile) calcResFile.close() theRes = Anova2(calcResMtx) tt = '\t'+theRes['factors'][0]+'\t'+theRes['S'][0]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][0]+'\t'+theRes['F0'][0]+'\t'+F0_evaluate(theRes['F0'],2)[0]+'\n' \ +'\t'+theRes['factors'][1]+'\t'+theRes['S'][1]+'\t'+str(theRes['dofLevel'])+'\t' \ +theRes['sms'][1]+'\t'+theRes['F0'][1]+'\t'+F0_evaluate(theRes['F0'],2)[1]+'\n' \ +'\t'+theRes['factors'][2]+'\t'+theRes['Se']+'\t'+str(theRes['dofErr'])+'\t' +theRes['errSms']+'\n' \ +'\t'+theRes['factors'][3]+'\t'+theRes['ST']+'\t'+str(theRes['dofSum']) f3_res.delete('1.0', END) f3_res.insert('1.0', tt) txt_optLevel.delete(0, END) txt_optLevel.insert(0, theRes['optLevel']) else: showwarning('项目选择错误','请选择至少两项')
#===================== 界面设计 =========================== root = Tk() top = Frame(root) top.pack(side='top') #========定义字体============ font_chs = ('宋体', 12) font_eng = ('Times', 12) #==========标题==================== lbl_Title = Label(top, text='柴油机结构系统优化软件', font=('宋体', 16)).pack(side='top', padx=15, pady=10, ipadx=10, fill=X) #=============第1部分=============== f1 = LabelFrame(top, text='柴油机总体参数', font=font_chs) f1_1 = Frame(f1, padx=10) Label(f1_1, text='功率:', font=font_chs).pack(side='left') txt_power = Entry(f1_1, font=font_eng) txt_power.pack(side='left') f1_1.pack(side='left')
f1_2 = Frame(f1, padx=10) Label(f1_2, text='气缸数:', font=font_chs).pack(side='left') txt_cyNo = Entry(f1_2, font=font_eng) txt_cyNo.pack(side='left') f1_2.pack(side='left')
f1_3 = Frame(f1, padx=10) Label(f1_3, text='冲程数:', font=font_chs).pack(side='left') txt_strikeNo = Entry(f1_3, font=font_eng) txt_strikeNo.pack(side='left') f1_3.pack(side='left')
f1.pack(side='top', padx=15, pady=10, ipadx=10, ipady=10, fill=X)
#=============第2部分=============== f2 = LabelFrame(top, text='柴油机本体结构参数评价及优化', font=font_chs) f2_1 = Frame(f2, pady = 10) f2_1_1 = Frame(f2_1, padx=1) Label(f2_1_1, text='方案:', font=font_chs).pack(side='left') txt_sch = Text(f2_1_1, font=font_eng, height=3, width=40) txt_sch.pack(side='left') f2_1_1 .pack(side='left') f2_1_2 = Frame(f2_1, padx=10) Label(f2_1_2, text='试验结果:', font=font_chs).pack(side='left') txt_expRes = Text(f2_1_2, font=font_eng, height=3, width=10) txt_expRes.pack(side='left') f2_1_2 .pack(side='left') Button(f2_1, text='参数分析', font=font_chs, command=solve_7).pack(side='left',padx=40) f2_1.pack(side='top')
f2_2 = Frame(f2, padx=1) f2_2_1 = Frame(f2_2, padx=10) Label(f2_2_1, text='评价结果:', font=font_chs).pack(side='left') txt_optRes = Entry(f2_2_1, font=font_eng, bg='grey', width=32) txt_optRes.pack(side='left',anchor='c') f2_2_1.pack(side='left')
f2_2_2 = Frame(f2_2) Label(f2_2_2, text='优选方案:', font=font_chs).pack(side='left') txt_optSch = Entry(f2_2_2, font=font_eng, bg='grey', width=32) txt_optSch.pack(side='left',anchor='c') f2_2_2.pack(side='left') f2_2.pack(side='top',anchor='w') f2.pack(side='top', padx=15, pady=5, ipadx=1, ipady=10, fill=X)
#=============第3部分=============== f3 = LabelFrame(top, text='柴油机系统布置优化', font=font_chs) f3_top = Frame(f3) f3_1 = Frame(f3_top, padx=10) chkb1 = IntVar(); chkb2 = IntVar(); chkb3 = IntVar(); chkb4 = IntVar(); chkb5 = IntVar() chb_inlet = Checkbutton(f3_1, text='进排气系', font=font_chs, variable=chkb1) chb_inlet.pack(side='top', anchor='w') chb_lub = Checkbutton(f3_1, text='润滑系', font=font_chs, variable=chkb2) chb_lub.pack(side='top', anchor='w') chb_cool = Checkbutton(f3_1, text='冷却系', font=font_chs, variable=chkb3) chb_cool.pack(side='top', anchor='w') chb_start = Checkbutton(f3_1, text='起动系', font=font_chs, variable=chkb4) chb_start.pack(side='top', anchor='w') chb_turbo = Checkbutton(f3_1, text='增压器中冷装置', font=font_chs, variable=chkb5) chb_turbo.pack(side='top', anchor='w') f3_1.pack(side='left') f3_2 = Frame(f3_top, padx=10) Button(f3_2, text='求解', font=font_chs, command=solve_2345).pack(side='left') f3_2.pack(side='left') f3_3 = Frame(f3_top, padx=10) f3_3_1 = Frame(f3_3) Label(f3_3_1, text='方差来源', font=font_chs).pack(side='left', anchor='w') Label(f3_3_1, text='偏差平方和', font=font_chs).pack(side='left', padx=8) Label(f3_3_1, text='自由度', font=font_chs).pack(side='left', padx=8) Label(f3_3_1, text='方差', font=font_chs).pack(side='left', padx=25) Label(f3_3_1, text='F0值', font=font_chs).pack(side='left', padx=20) Label(f3_3_1, text='显著性', font=font_chs).pack(side='left', anchor='e', padx=4) f3_3_1.pack(side='top', fill=X, expand=1) f3_res = Text(f3_3, font=font_eng, bg='grey', height=7, width=65, tabs=('1c',CENTER,\ '3c',NUMERIC,'5.5c',NUMERIC,'7c',NUMERIC,'9.2c',NUMERIC,'11.5c',CENTER)) f3_res.pack(side='top') f3_3.pack(side='left') f3_top.pack(side='top')
f3_bottom = Frame(f3, pady =10) Label(f3_bottom, text='优水平:', font=font_chs).pack(side='left') txt_optLevel = Entry(f3_bottom, font=font_eng, bg='grey', width=32) txt_optLevel.pack(side='left',anchor='c') f3_bottom.pack(side='top', anchor='e', ipadx=90)
f3.pack(side='top', padx=15, pady=10, ipadx=10, ipady=10, fill=X)
root.title('柴油机结构系统优化软件') root.mainloop()