利用python写的一个小软件,最近一直做流水线,使用西门子PLC读写变频器速度,PLC给变频器写入和读取的速度参数计算公式如下:
Rel=16384/(电机转速/减速比3.14辊筒直径)
电机很多时,计算量很大,写了这个小软件,方便计算。
软件运行界面如下
通过pyinstaller打包生成了可执行文件。
原代码如下:
#!/usr/bin/python
# _*_coding:utf-8_*_
__author__ = 'wangXiaolan'
# Python imports
from tkinter import *
#import tkFileDialog
import tkinter.messagebox as msbox
#global filename_g
#定义标签
class myLabel():
def __init__(self,root,text,row_set,column_set):
self.root=root
self.text=text
self.row_set=row_set
self.column_set=column_set
def creatText(self):
Label(self.root,text=self.text).grid(row=self.row_set,column=self.column_set)
#定义输入框,state_set可以为disabled,normal,readonly,如果不给定输入,默认是正常状态
class myEntry():
def __init__(self,root,textvariable,row_set,column_set):
self.root=root
self.textvariable=textvariable
self.row_set=row_set
self.column_set=column_set
def creatEntry(self,state_set="normal"):
self.state=state_set
self.var=StringVar()
Entry(self.root,textvariable=self.var,state=self.state,width=16).grid(row=self.row_set,column=self.column_set)
#return self.var.get()
def getvar(self):
return self.var.get()
def show():
#print var1.var.get3()
var_show1=(var1.getvar()).strip()
var_show2=(var2.getvar()).strip()
var_show3=(var3.getvar()).strip()
AlarmInputCheack(var_show1)
AlarmInputCheack(var_show2)
AlarmInputCheack(var_show3)
var5.var.set(float(var_show1)/float(var_show2)*3.1415926*float(var_show3))
var4.var.set(16384.0/float(var5.var.get()))
def AlarmMessagebox():
msbox.showinfo("错误","输入值错误")
#将输入的字符“.”,替换成“”,然后进项检测,如果不全是数字就报警
def AlarmInputCheack(var):
Alarm_var=var.replace(".","")
if not Alarm_var.isdigit():
AlarmMessagebox()
win=Tk()
win.title("西门子变频器系数计算")
win.maxsize(255,150)
win.minsize(255,150)
win.geometry("200x220+400+300")
nametitle1=myLabel(win,"电机额定转速",0,0)
nametitle1.creatText()
nametitle2=myLabel(win,"电机减速比",1,0)
nametitle2.creatText()
nametitle3=myLabel(win,"辊筒直径",2,0)
nametitle3.creatText()
nametitle4=myLabel(win,"rpm",0,2)
nametitle4.creatText()
var1=myEntry(win,0.0,0,1)
var1.creatEntry()
var1.var.set("1200")
var2=myEntry(win,0.0,1,1)
var2.creatEntry()
var2.var.set("1.0")
var3=myEntry(win,0.0,2,1)
var3.creatEntry()
var3.var.set("1.0")
nametitle4=myLabel(win,"M",2,2)
nametitle4.creatText()
var4=myEntry(win,0.0,4,1)
var4.creatEntry("readonly")
nametitle5=myLabel(win,"最大线速度",3,0)
nametitle5.creatText()
var5=myEntry(win,0.0,3,1)
var5.creatEntry("readonly")
nametitle6=myLabel(win,"M/min",3,2)
nametitle6.creatText()
Button(win,text="计算",command=show,width=8).grid(row=4,column=0)
Button(win,text="退出",command=win.quit,width=6).grid(row=4,column=2)
Label(win,text="Rel=16384/(电机转速/减速比*3.14*辊筒直径)").grid(row=5,column=0,columnspan=3)
mainloop()