This article has shared the specific code of wxPython color ring resistor calculator for your reference. The specific content is as follows
import wx # Import wxPythonclass MyFrame(): def __init__(self,parent,id): .__init__(self, parent, id, "Color Ring Resistance Calculator 2.0",size=(600,450)) = (self) # Create artboard (set program title, size) self.font1 = (20,,wx.FONTSTYLE_NORMAL,,faceName="Bold") self.font2 = (16,,wx.FONTSTYLE_NORMAL,,faceName="Bold") = ['black', 'Brown', 'red', 'orange', 'yellow', 'green', 'blue', 'purple', 'Ash', 'white', 'gold', 'silver'] self.choices2 = ['black', 'Brown', 'red', 'green', 'blue', 'purple', 'Ash', 'gold', 'silver'] 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'] = True self.Init_Panel() def Init_Panel(self): self.Create_display_part() self.Create_resistant() self.bt_change = (, label='Switch to 4 color ring', 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.() self.() self.() self.() self.colour_1.Destroy() self.colour_2.Destroy() self.colour_3.Destroy() self.colour_4.Destroy() if == True: self.bt_change.SetLabel('Switch to 5 color ring') self.() self.colour_5.Destroy() self.Create_display4() = False else: self.bt_change.SetLabel('Switch to 4 color ring') self.Create_display5() = True def Event_radiobox(self,event): self.colour_1.Destroy() self.colour_2.Destroy() self.colour_3.Destroy() self.colour_4.Destroy() one = self.() two = self.() three = self.() four = self.() if == True: self.colour_5.Destroy() five = self.() if four > 9: temp = 9 - four else: temp = four result = (one * 100 + two * 10 + three) * (pow(10, temp)) error = self.error_code[five] (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] (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 = (, label="Resistance:",pos=(400,25)) label_error = (, label="Error: ±",pos=(400,125)) label_percentage = (, label="%",pos=(520,150)) self.label_ohm = (, label="Ω", pos=(520, 50)) self.text_resistance = (, value='0.00',pos=(400, 50), style=wx.TE_RIGHT | wx.TE_READONLY) self.text_error = (, 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 = (, pos=(170, 330), size=(240, 50)) ('light blue') left_pin = (, pos=(20, 350), size=(150, 5)) left_pin.SetBackgroundColour('white') right_pin = (, pos=(410, 350), size=(150, 5)) right_pin.SetBackgroundColour('white') def Create_display4(self): self.radiobox1 = self.Create_radiobox('1',0,[:-2]) self.radiobox2 = self.Create_radiobox('2',100, [:-2]) self.radiobox3 = self.Create_radiobox('3',200, [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, [:-2]) self.radiobox2 = self.Create_radiobox('2', 75, [:-2]) self.radiobox3 = self.Create_radiobox('3', 150, [:-2]) self.radiobox4 = self.Create_radiobox('4', 225, ) 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 = 'Part' + label_num + 'Bit' pos = (abscissa,0) radiobox = (, -1, label, pos, choices=choices, majorDimension=1) (wx.EVT_RADIOBOX, self.Event_radiobox) return radiobox def Create_Colourbar(self,abscissa,colour): pos = (abscissa,330) colour_bar = (,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 = () myframe = MyFrame(None,-1) () ()
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.