侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

wxPython色环电阻计算器

Python  /  管理员 发布于 7年前   236

本文实例为大家分享了wxPython色环电阻计算器的具体代码,供大家参考,具体内容如下

import wx # 导入wxPythonclass MyFrame(wx.Frame): def __init__(self,parent,id):  wx.Frame.__init__(self, parent, id, "色环电阻计算器2.0",size=(600,450))  self.panel = wx.Panel(self) # 创建画板(设置程序标题,大小)  self.font1 = wx.Font(20,wx.DEFAULT,wx.FONTSTYLE_NORMAL,wx.NORMAL,faceName="黑体")  self.font2 = wx.Font(16,wx.DEFAULT,wx.FONTSTYLE_NORMAL,wx.NORMAL,faceName="黑体")  self.choices = ['黑', '棕', '红', '橙', '黄', '绿', '蓝', '紫', '灰', '白', '金', '银']  self.choices2 = ['黑', '棕', '红', '绿', '蓝', '紫', '灰', '金', '银']  self.choices3 = ['black','brown','red','coral','yellow','green','blue','purple','grey','white','gold','light grey']  self.choices4 = ['black','brown','red','green','blue','purple','grey','gold','light grey']  self.error_code = ['20', '1', '2', '0.5', '0.25', '0.1', '0.05', '5', '10']  self.IsFive = True  self.Init_Panel() def Init_Panel(self):  self.Create_display_part()  self.Create_resistant()  self.bt_change = wx.Button(self.panel, label='切换为4色环', pos=(400, 250), size=(150, 50))  self.bt_change.SetFont(self.font2)  self.bt_change.Bind(wx.EVT_BUTTON, self.Event_Change)  self.Create_display5() def Event_Change(self,event):  self.radiobox1.Destroy()  self.radiobox2.Destroy()  self.radiobox3.Destroy()  self.radiobox4.Destroy()  self.colour_1.Destroy()  self.colour_2.Destroy()  self.colour_3.Destroy()  self.colour_4.Destroy()  if self.IsFive == True:   self.bt_change.SetLabel('切换为5色环')   self.radiobox5.Destroy()   self.colour_5.Destroy()   self.Create_display4()   self.IsFive = False  else:   self.bt_change.SetLabel('切换为4色环')   self.Create_display5()   self.IsFive = True def Event_radiobox(self,event):  self.colour_1.Destroy()  self.colour_2.Destroy()  self.colour_3.Destroy()  self.colour_4.Destroy()  one = self.radiobox1.GetSelection()  two = self.radiobox2.GetSelection()  three = self.radiobox3.GetSelection()  four = self.radiobox4.GetSelection()  if self.IsFive == True:   self.colour_5.Destroy()   five = self.radiobox5.GetSelection()   if four > 9:    temp = 9 - four   else:    temp = four   result = (one * 100 + two * 10 + three) * (pow(10, temp))   error = self.error_code[five]   self.display(result, error)   self.colour_1 = self.Create_Colourbar(200, self.choices3[one])   self.colour_2 = self.Create_Colourbar(240, self.choices3[two])   self.colour_3 = self.Create_Colourbar(280, self.choices3[three])   self.colour_4 = self.Create_Colourbar(320, self.choices3[four])   self.colour_5 = self.Create_Colourbar(360, self.choices4[five])  else:   if three > 8:    temp = 8 - three   else:    temp = three + 1   result = (one * 10 + two) * (pow(10, temp))   error = self.error_code[four]   self.display(result, error)   self.colour_1 = self.Create_Colourbar(200, self.choices3[one])   self.colour_2 = self.Create_Colourbar(250, self.choices3[two])   self.colour_3 = self.Create_Colourbar(300, self.choices3[three + 1])   self.colour_4 = self.Create_Colourbar(350, self.choices4[four]) def Create_display_part(self):  label_resistance = wx.StaticText(self.panel, label="阻值:",pos=(400,25))  label_error = wx.StaticText(self.panel, label="误差:±",pos=(400,125))  label_percentage = wx.StaticText(self.panel, label="%",pos=(520,150))  self.label_ohm = wx.StaticText(self.panel, label="Ω", pos=(520, 50))  self.text_resistance = wx.TextCtrl(self.panel, value='0.00',pos=(400, 50), style=wx.TE_RIGHT | wx.TE_READONLY)  self.text_error = wx.TextCtrl(self.panel, value='20',pos=(400, 150), style=wx.TE_RIGHT | wx.TE_READONLY)  label_resistance.SetFont(self.font2)  label_error.SetFont(self.font2)  label_percentage.SetFont(self.font2)  self.label_ohm.SetFont(self.font2)  self.text_resistance.SetFont(self.font2)  self.text_error.SetFont(self.font2)  self.text_resistance.SetBackgroundColour('white')  self.text_error.SetBackgroundColour('white') def Create_resistant(self):  body = wx.StaticText(self.panel, pos=(170, 330), size=(240, 50))  body.SetBackgroundColour('light blue')  left_pin = wx.StaticText(self.panel, pos=(20, 350), size=(150, 5))  left_pin.SetBackgroundColour('white')  right_pin = wx.StaticText(self.panel, pos=(410, 350), size=(150, 5))  right_pin.SetBackgroundColour('white') def Create_display4(self):  self.radiobox1 = self.Create_radiobox('1',0,self.choices[:-2])  self.radiobox2 = self.Create_radiobox('2',100, self.choices[:-2])  self.radiobox3 = self.Create_radiobox('3',200, self.choices[1:])  self.radiobox4 = self.Create_radiobox('4',300, self.choices2)  self.colour_1 = self.Create_Colourbar(200,'black')  self.colour_2 = self.Create_Colourbar(250,'black')  self.colour_3 = self.Create_Colourbar(300,'brown')  self.colour_4 = self.Create_Colourbar(350,'black') def Create_display5(self):  self.radiobox1 = self.Create_radiobox('1', 0, self.choices[:-2])  self.radiobox2 = self.Create_radiobox('2', 75, self.choices[:-2])  self.radiobox3 = self.Create_radiobox('3', 150, self.choices[:-2])  self.radiobox4 = self.Create_radiobox('4', 225, self.choices)  self.radiobox5 = self.Create_radiobox('5', 300, self.choices2)  self.colour_1 = self.Create_Colourbar(200, 'black')  self.colour_2 = self.Create_Colourbar(240, 'black')  self.colour_3 = self.Create_Colourbar(280, 'black')  self.colour_4 = self.Create_Colourbar(320, 'black')  self.colour_5 = self.Create_Colourbar(360, 'black') def Create_radiobox(self, label_num, abscissa, choices):  label = '第' + label_num + '位'  pos = (abscissa,0)  radiobox = wx.RadioBox(self.panel, -1, label, pos, choices=choices, majorDimension=1)  radiobox.Bind(wx.EVT_RADIOBOX, self.Event_radiobox)  return radiobox def Create_Colourbar(self,abscissa,colour):  pos = (abscissa,330)  colour_bar = wx.StaticText(self.panel,pos=pos, size=(30, 50))  colour_bar.SetBackgroundColour(colour)  return colour_bar def display(self,a,b):  if a>=1000000:   a="%.2f"%(a/1000000)   self.label_ohm.SetLabel('MΩ')  elif 1000<=a<=1000000:   a="%.2f"%(a/1000)   self.label_ohm.SetLabel('KΩ')  else:   a="%.2f"%(a)   self.label_ohm.SetLabel('Ω')  self.text_resistance.SetValue(a)  self.text_error.SetValue(b)if __name__ =='__main__': app = wx.App() myframe = MyFrame(None,-1) myframe.Show() app.MainLoop()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    python 实现绘制整齐的表格
    下一条:
    Python模拟登录之滑块验证码的破解(实例代码)
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在python语言中Flask框架的学习及简单功能示例(0个评论)
    • 在Python语言中实现GUI全屏倒计时代码示例(0个评论)
    • Python + zipfile库实现zip文件解压自动化脚本示例(0个评论)
    • python爬虫BeautifulSoup快速抓取网站图片(1个评论)
    • vscode 配置 python3开发环境的方法(0个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2018-04
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2022-01
    • 2023-07
    • 2023-10
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客