日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

基于python3.7的4环电阻读数工具

發布時間:2024/3/7 python 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于python3.7的4环电阻读数工具 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


PS:圖片是網上找的

效果圖:

#!/usr/bin/python # -*- coding: UTF-8 -*-import tkinter as tk from tkinter import ttk from PIL import Image,ImageDraw,ImageTk# 名稱 段值 乘數 誤差 pcolor=( ('黑','black' ,0, 1, 'Ω', ''), ('棕','brown' ,1, 10, 'Ω', '±1%'), ('紅','red' ,2, 100,'Ω', '±2%'), ('橙','orange' ,3, 1, 'K',''), ('黃','yellow' ,4, 10, 'K',''), ('綠','green' ,5, 100,'K','±0.5%'), ('藍','blue' ,6, 1, 'M','±0.25%'), ('紫','violet' ,7, 10, 'M','±0.1%'), ('灰','grey' ,8, '', 'Ω', '±0.05%'), ('白','white' ,9, '', 'Ω', ''), ('金','gold' ,'',0.1,'Ω', '±5%'), ('銀','silver' ,'',0.01,'Ω','±10%') )#1段、2段、3段、乘數、誤差 pres=['','','','','']# 畫面 工具-編程工具 class AppFrameC51Resistor4():#master為Tk()對象def __init__(self, master):self.initface = tk.Frame(master, )self.initface.grid(row=0, column=0)#----------------------------- 電阻計算self.view_1()#----------------------------- #----------------------------- #----------------------------- #----------------------------- #色環電阻的識別def view_1(self):face1 = tk.Frame(self.initface)face1.grid(row=0, column=0)tk.Label(face1, text='色環電阻').grid(row=0, column=0, sticky=tk.W)im = Image.open('color_resistor.jpg')im = im.resize((370,412), Image.ANTIALIAS)img_png = ImageTk.PhotoImage(im)imglabel = tk.Label(face1)imglabel.grid(row=1,column=0, rowspan=30)imglabel.configure(image=img_png)imglabel.image = img_pngtk.Label(face1, text='第一段').grid(row=2, column=1)self.tk_face1_f1 = tk.Label(face1, text='無')self.tk_face1_f1.grid(row=2, column=2)for i in range(10):tk.Button(face1, text=pcolor[i][0], bg=pcolor[i][1], command=lambda i=i: self.face1_btn1_click(i)).grid(row=2, column=i+3)tk.Label(face1, text='第二段').grid(row=3, column=1)self.tk_face1_f2 = tk.Label(face1, text='無')self.tk_face1_f2.grid(row=3, column=2)for i in range(10):tk.Button(face1, text=pcolor[i][0], bg=pcolor[i][1], command=lambda i=i: self.face1_btn2_click(i)).grid(row=3, column=i+3)tk.Label(face1, text='乘數').grid(row=5, column=1)self.tk_face1_fc = tk.Label(face1, text='無')self.tk_face1_fc.grid(row=5, column=2)for i in range(12):if i not in(8,9):tk.Button(face1, text=pcolor[i][0], bg=pcolor[i][1], command=lambda i=i: self.face1_btnc_click(i)).grid(row=5, column=i+3)tk.Label(face1, text='誤差').grid(row=6, column=1)self.tk_face1_fw = tk.Label(face1, text='無')self.tk_face1_fw.grid(row=6, column=2)for i in range(12):if i not in(0,3,4,9):tk.Button(face1, text=pcolor[i][0], bg=pcolor[i][1], command=lambda i=i: self.face1_btnw_click(i)).grid(row=6, column=i+3)tk.Label(face1, text='電阻').grid(row=7, column=1)self.tk_face1_res_v = tk.Label(face1, text='')self.tk_face1_res_v.grid(row=7, column=2, columnspan=3)tk.Label(face1, text='誤差').grid(row=8, column=1)self.tk_face1_res_f = tk.Label(face1, text='')self.tk_face1_res_f.grid(row=8, column=2, columnspan=3)def face1_btn1_click(self,i):self.tk_face1_f1['bg']=pcolor[i][1]self.tk_face1_f1['text']=pcolor[i][0]pres[0] = iself.face1_res_calc()def face1_btn2_click(self,i):self.tk_face1_f2['bg']=pcolor[i][1]self.tk_face1_f2['text']=pcolor[i][0]pres[1] = iself.face1_res_calc()def face1_btnc_click(self,i):self.tk_face1_fc['bg']=pcolor[i][1]self.tk_face1_fc['text']=pcolor[i][0]pres[3] = iself.face1_res_calc()def face1_btnw_click(self,i):self.tk_face1_fw['bg']=pcolor[i][1]self.tk_face1_fw['text']=pcolor[i][0]pres[4] = iself.face1_res_calc()def face1_res_calc(self):#誤差if pres[4]!='':self.tk_face1_res_f['text']=pcolor[pres[4]][5]fvalue=0funit=''if pres[0]=='' or pres[1]=='' or pres[3]=='' or pres[4]=='':returnfvalue=pcolor[pres[0]][2]*10+pcolor[pres[1]][2]fvalue=fvalue * pcolor[pres[3]][3]funit=pcolor[pres[3]][4]if fvalue>1000 and funit!='M':fvalue=fvalue/1000if funit=='Ω':funit='K'elif funit=='K':funit='M'else:passself.tk_face1_res_v['text']=str(round(fvalue,2))+funitdef destory(self, ):self.initface.destroy()def setCenter(groot):winWidth,winHeight = 800,600groot.title("我的工具")screenWidth = groot.winfo_screenwidth()screenHeight = groot.winfo_screenheight()x = int((screenWidth - winWidth) / 2)y = int((screenHeight - winHeight) / 2)# 設置窗口初始位置在屏幕居中groot.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))# 設置窗口寬高固定groot.resizable(0, 0)if __name__ == "__main__":groot = tk.Tk() #窗口setCenter(groot)AppFrameC51Resistor4(groot)groot.mainloop()

總結

以上是生活随笔為你收集整理的基于python3.7的4环电阻读数工具的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。