欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

自学python---02_谐波计算工具开发

程序员文章站 2022-03-16 22:59:18
一 开发环境说明: python3.5+wxpython包+math包 win10环境下开发,兼任win7 编译工具:pycharm 二 运行界面展示: 三 开源共享: 四 打包xe文件下载地址: 百度网盘:https://pan.baidu.com/s/1xn9hjBsAvCFFq8XSpqS0L ......

一 开发环境说明:

  python3.5+wxpython包+math包

  win10环境下开发,兼任win7

  编译工具:pycharm

 

二 运行界面展示:

 自学python---02_谐波计算工具开发

 

 三 开源共享: 

  1 #! /user/bin/env python
  2 #coding=utf-8
  3 import sys
  4 sys.path.append('c:\program files\python35\lib\site-packages')
  5 import wx
  6 import math
  7 
  8 class myframe(wx.frame):
  9     def __init__(self):
 10         wx.frame.__init__(self,none,-1,"谐波计算_chenyuyang",size=(1100,400),style=wx.default_frame_style^(wx.resize_border | wx.minimize_box | wx.maximize_box))
 11         self.center()
 12         panel = wx.panel(parent=self)
 13         panel.center()
 14         font = wx.font(16,wx.roman,wx.normal,wx.bold,underline=false)
 15         self.equation = ""
 16         self.result = 0
 17         self.resultflag = 0
 18 
 19         self.lab1 = wx.statictext(panel,-1,"\n参考时钟(mhz):",pos=(60,40),size=(190,30))
 20         self.lab1.setfont(font)
 21         self.text1 = wx.textctrl(panel,-1,pos=(180,10),size=(70,35))
 22 
 23         self.lab2 = wx.statictext(panel,-1,"分频比:",pos=(260,22),size=(180,30))
 24         self.lab2.setfont(font)
 25         self.text2 = wx.textctrl(panel,-1,pos=(350,10),size=(70,35))
 26 
 27         self.lab3 = wx.statictext(panel,-1,"n次谐波:",pos=(440,22),size=(180,30))
 28         self.lab3.setfont(font)
 29         self.text3 = wx.textctrl(panel,-1,pos=(550,10),size=(70,35))
 30 
 31         self.lab4 = wx.statictext(panel,-1,"谐波值:",pos=(630,22),size=(180,30))
 32         self.lab4.setfont(font)
 33         self.text4 = wx.textctrl(panel,-1,pos=(720,10),size=(90,35))
 34 
 35         self.button1 = wx.button(panel,-1,"计算",pos=(850,10),size=(80,40))
 36         self.button1.setfont(font)
 37         self.button1.bind(wx.evt_button,self.oneclick)
 38 
 39 
 40         self.button2 = wx.button(panel,-1,"清除",pos=(1000,10),size=(80,40))
 41         self.button2.setfont(font)
 42         self.button2.bind(wx.evt_button,self.oneclick1)
 43 
 44         boxsize = wx.boxsizer(wx.vertical)
 45         boxsize.add(self.lab1,1)
 46 
 47 
 48         self.button2.backgroundcolour = 'pink'
 49         self.button1.backgroundcolour = 'aquamarine'
 50 
 51         gridsizer = wx.gridsizer(cols=10,rows=4,vgap=0,hgap=0)
 52 
 53         for i in range(0,10):
 54             g = i +1
 55             exec("self.btn%s = wx.button(panel,label='%s')"%(i,g))
 56             # exec("self.btn%s.backgroundcolour = 'pale green'"%i)
 57             # self.btn0 = wx.button(panel,label="1")
 58         for i in range(10,20):
 59             exec("self.btn%s = wx.textctrl(panel,-1,'')"%i)
 60 
 61         for i in range(20,30):
 62             k = i + 1
 63             exec("self.btn%s = wx.button(panel,label='%s')"%(i,k))
 64 
 65         for i in range(30,40):
 66             exec("self.btn%s = wx.textctrl(panel,-1,'')"%i)
 67 
 68         for i in range(0,40):
 69             exec("self.btn%s.setfont(font)"%i)
 70 
 71         gridsizer.addmany([(self.btn0,0,wx.expand),
 72                            (self.btn1,0,wx.expand),
 73                            (self.btn2,0,wx.expand),
 74                            (self.btn3, 0, wx.expand),
 75                            (self.btn4, 0, wx.expand),
 76                            (self.btn5, 0, wx.expand),
 77                            (self.btn6, 0, wx.expand),
 78                            (self.btn7, 0, wx.expand),
 79                            (self.btn8, 0, wx.expand),
 80                            (self.btn9, 0, wx.expand),
 81                            (self.btn10, 0, wx.expand),
 82                            (self.btn11, 0, wx.expand),
 83                            (self.btn12, 0, wx.expand),
 84                            (self.btn13, 0, wx.expand),
 85                            (self.btn14, 0, wx.expand),
 86                            (self.btn15, 0, wx.expand),
 87                            (self.btn16, 0, wx.expand),
 88                            (self.btn17, 0, wx.expand),
 89                            (self.btn18, 0, wx.expand),
 90                            (self.btn19, 0, wx.expand),
 91                            (self.btn20, 0, wx.expand),
 92                            (self.btn21, 0, wx.expand),
 93                            (self.btn22, 0, wx.expand),
 94                            (self.btn23, 0, wx.expand),
 95                            (self.btn24, 0, wx.expand),
 96                            (self.btn25, 0, wx.expand),
 97                            (self.btn26, 0, wx.expand),
 98                            (self.btn27, 0, wx.expand),
 99                            (self.btn28, 0, wx.expand),
100                            (self.btn29, 0, wx.expand),
101                            (self.btn30, 0, wx.expand),
102                            (self.btn31, 0, wx.expand),
103                            (self.btn32, 0, wx.expand),
104                            (self.btn33, 0, wx.expand),
105                            (self.btn34, 0, wx.expand),
106                            (self.btn35, 0, wx.expand),
107                            (self.btn36, 0, wx.expand),
108                            (self.btn37, 0, wx.expand),
109                            (self.btn38, 0, wx.expand),
110                            (self.btn39, 0, wx.expand)])
111 
112         for i in range (0,10):
113             exec("self.btn%s.backgroundcolour = 'pale green'"%i)
114 
115         for i in range(20,30):
116             exec("self.btn%s.backgroundcolour = 'pale green'"%i)
117 
118         boxsize.add(gridsizer,6,wx.expand)
119         panel.setsizerandfit(boxsize)
120 
121     def oneclick(self,event):
122         str11 = self.text1.getvalue()
123         a14 = float(str11)
124 
125         str1 = self.text2.getvalue()
126         a1=float(str1)
127         a2=int(a1)
128 
129         a3 = a1 - a2
130 
131         a5 =1
132         a4 = a3
133         str5 = math.modf(a4)
134         a6 = str5[0]
135         a7 = float(a6)
136         if a7 < 0.5:
137             a8 = a7*a14
138         else:
139             a8 =(1-a7)*a1
140         self.btn10.setvalue('%.3f' % a8)
141 
142         a5 =2
143         a4 = a3 * a5
144         str5 = math.modf(a4)
145         a6 = str5[0]
146         a7 = float(a6)
147         if a7 < 0.5:
148             a8 = a7*a14
149         else:
150             a8 =(1-a7)*a1
151         self.btn11.setvalue('%.3f' % a8)
152 
153 
154         a5 =3
155         a4 = a3 * a5
156         str5 = math.modf(a4)
157         a6 = str5[0]
158         a7 = float(a6)
159         if a7 < 0.5:
160             a8 = a7*a14
161         else:
162             a8 =(1-a7)*a1
163         self.btn12.setvalue('%.3f' % a8)
164 
165 
166         a5 =4
167         a4 = a3 * a5
168         str5 = math.modf(a4)
169         a6 = str5[0]
170         a7 = float(a6)
171         if a7 < 0.5:
172             a8 = a7*a14
173         else:
174             a8 =(1-a7)*a1
175         self.btn13.setvalue('%.3f' % a8)
176 
177 
178         a5 =5
179         a4 = a3 * a5
180         str5 = math.modf(a4)
181         a6 = str5[0]
182         a7 = float(a6)
183         if a7 < 0.5:
184             a8 = a7*a14
185         else:
186             a8 =(1-a7)*a1
187         self.btn14.setvalue('%.3f' % a8)
188 
189 
190         a5 =6
191         a4 = a3 * a5
192         str5 = math.modf(a4)
193         a6 = str5[0]
194         a7 = float(a6)
195         if a7 < 0.5:
196             a8 = a7*a14
197         else:
198             a8 =(1-a7)*a1
199         self.btn15.setvalue('%.3f' % a8)
200 
201 
202         a5 =7
203         a4 = a3 * a5
204         str5 = math.modf(a4)
205         a6 = str5[0]
206         a7 = float(a6)
207         if a7 < 0.5:
208             a8 = a7*a14
209         else:
210             a8 =(1-a7)*a1
211         self.btn16.setvalue('%.3f' % a8)
212 
213 
214         a5 =8
215         a4 = a3 * a5
216         str5 = math.modf(a4)
217         a6 = str5[0]
218         a7 = float(a6)
219         if a7 < 0.5:
220             a8 = a7*a14
221         else:
222             a8 =(1-a7)*a1
223         self.btn17.setvalue('%.3f' % a8)
224 
225 
226 
227         a5 =9
228         a4 = a3 * a5
229         str5 = math.modf(a4)
230         a6 = str5[0]
231         a7 = float(a6)
232         if a7 < 0.5:
233             a8 = a7*a14
234         else:
235             a8 =(1-a7)*a1
236         self.btn18.setvalue('%.3f' % a8)
237 
238         a5 =10
239         a4 = a3 * a5
240         str5 = math.modf(a4)
241         a6 = str5[0]
242         a7 = float(a6)
243         if a7 < 0.5:
244             a8 = a7*a14
245         else:
246             a8 =(1-a7)*a1
247         self.btn19.setvalue('%.3f' % a8)
248 
249         a5 =11
250         a4 = a3 * a5
251         str5 = math.modf(a4)
252         a6 = str5[0]
253         a7 = float(a6)
254         if a7 < 0.5:
255             a8 = a7*a14
256         else:
257             a8 =(1-a7)*a1
258         self.btn30.setvalue('%.3f' % a8)
259 
260 
261         a5 =12
262         a4 = a3 * a5
263         str5 = math.modf(a4)
264         a6 = str5[0]
265         a7 = float(a6)
266         if a7 < 0.5:
267             a8 = a7*a14
268         else:
269             a8 =(1-a7)*a1
270         self.btn31.setvalue('%.3f' % a8)
271 
272 
273         a5 =13
274         a4 = a3 * a5
275         str5 = math.modf(a4)
276         a6 = str5[0]
277         a7 = float(a6)
278         if a7 < 0.5:
279             a8 = a7*a14
280         else:
281             a8 =(1-a7)*a1
282         self.btn32.setvalue('%.3f' % a8)
283 
284 
285         a5 =14
286         a4 = a3 * a5
287         str5 = math.modf(a4)
288         a6 = str5[0]
289         a7 = float(a6)
290         if a7 < 0.5:
291             a8 = a7*a14
292         else:
293             a8 =(1-a7)*a1
294         self.btn33.setvalue('%.3f' % a8)
295 
296         a5 =15
297         a4 = a3 * a5
298         str5 = math.modf(a4)
299         a6 = str5[0]
300         a7 = float(a6)
301         if a7 < 0.5:
302             a8 = a7*a14
303         else:
304             a8 =(1-a7)*a1
305         self.btn34.setvalue('%.3f' % a8)
306 
307 
308         a5 =16
309         a4 = a3 * a5
310         str5 = math.modf(a4)
311         a6 = str5[0]
312         a7 = float(a6)
313         if a7 < 0.5:
314             a8 = a7*a14
315         else:
316             a8 =(1-a7)*a1
317         self.btn35.setvalue('%.3f' % a8)
318 
319 
320         a5 =17
321         a4 = a3 * a5
322         str5 = math.modf(a4)
323         a6 = str5[0]
324         a7 = float(a6)
325         if a7 < 0.5:
326             a8 = a7*a14
327         else:
328             a8 =(1-a7)*a1
329         self.btn36.setvalue('%.3f' % a8)
330 
331 
332         a5 =18
333         a4 = a3 * a5
334         str5 = math.modf(a4)
335         a6 = str5[0]
336         a7 = float(a6)
337         if a7 < 0.5:
338             a8 = a7*a14
339         else:
340             a8 =(1-a7)*a1
341         self.btn37.setvalue('%.3f' % a8)
342 
343 
344         a5 =19
345         a4 = a3 * a5
346         str5 = math.modf(a4)
347         a6 = str5[0]
348         a7 = float(a6)
349         if a7 < 0.5:
350             a8 = a7*a14
351         else:
352             a8 =(1-a7)*a1
353         self.btn38.setvalue('%.3f' % a8)
354 
355 
356         a5 =20
357         a4 = a3 * a5
358         str5 = math.modf(a4)
359         a6 = str5[0]
360         a7 = float(a6)
361         if a7 < 0.5:
362             a8 = a7*a14
363         else:
364             a8 =(1-a7)*a1
365         self.btn39.setvalue('%.3f' % a8)
366 
367         # for i in range(1,21):
368         #
369         #     a5 =i
370         #
371         #     a4 = a5 * a3
372         #
373         #     str5 = math.modf(a4)
374         #     a6 = str5[0]
375         #     a7 = float(a6)
376         #     if a7 < 0.5:
377         #         a8 = a7*a14
378         #     else:
379         #         a8 =(1-a7)*a1
380         #
381         #
382         #     j = a5 + 9
383         #
384         #     if j <20:
385         #
386         #         self.btn10.setvalue('%.3f'%a8)
387         #     #     # exec("self.btn%s.setvalue(%.3f)"%(j,a8))
388         #     #
389         #     #
390         #     # else:
391         #     #     k = i + 19
392         #     #     # exec("self.btn%s.setvalue(%.3f)"%(k,a8))
393 
394         str11 = self.text1.getvalue()
395         a14 = float(str11)
396 
397         str1 = self.text2.getvalue()
398         a1 = float(str1)
399         a2 = int(a1)
400         a3 = a1 -a2
401 
402         str3 = self.text3.getvalue()
403         a5 = float(str3)
404 
405         a4 = a3 * a5
406         str5 = math.modf(a4)
407         a6 = str5[0]
408         a7 = float(a6)
409 
410         if a7 < 0.5:
411             a8 = a7 * a14
412 
413         else:
414             a8 = (1-a7)*a14
415 
416         self.text4.setvalue("%.6f"%a8)
417 
418 
419     def oneclick1(self,event):
420         for i in range(1,3):
421             exec("self.text%s.clear()"%i)
422 
423 
424         for i in range(10, 20):
425             exec("self.btn%s.clear()" % i)
426 
427 
428         for i in range(30, 40):
429             exec("self.btn%s.clear()" % i)
430 
431 
432 class app(wx.app):
433     def oninit(self):
434         self.cyy = myframe()
435         self.cyy.bind(wx.evt_close,self.onclose,self.cyy)
436         self.cyy.show()
437         return true
438 
439 
440 
441     def onclose(self,event):
442         dlg = wx.messagedialog(none,"是否要关闭窗口?","请确认",wx.yes_no|wx.icon_question)
443         retcode = dlg.showmodal()
444         if(retcode == wx.id_yes):
445             self.cyy.destroy()
446         else:
447             pass
448 
449 
450 if __name__ =="__main__" :
451     app = app()
452     app.mainloop()

四 打包xe文件下载地址:

  百度网盘:https://pan.baidu.com/s/1xn9hjbsavcffq8xspqs0la