一 開發環境說明: python3.5+wxpython包+math包 win10環境下開發,兼任win7 編譯工具:pycharm 二 運行界面展示: 三 開源共用: 四 打包xe文件下載地址: 百度網盤:https://pan.baidu.com/s/1xn9hjBsAvCFFq8XSpqS0L ...
一 開發環境說明:
python3.5+wxpython包+math包
win10環境下開發,兼任win7
編譯工具:pycharm
二 運行界面展示:
三 開源共用:
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