代码拉取完成,页面将自动刷新
#-*-coding:gb2312-*-
import threading
import time
import os
import re
import sys
from tkinter import *
class CLK():
def __init__(self, value, unit, flag):
self.value = float(value)
self.unit = unit
self.flag = flag
def __str__(self):
ret = ""
ret += str(self.Hz_value) + "Hz\n"
ret += str(self.KHz_value) + "KHz\n"
ret += str(self.MHz_value) + "MHz\n"
ret += str(self.GHz_value) + "GHz\n"
ret += str(self.THz_value) + "THz\n"
ret += "\n"
ret += str(self.s_value) + "s\n"
ret += str(self.ms_value) + "ms\n"
ret += str(self.us_value) + "us\n"
ret += str(self.ns_value) + "ns\n"
ret += str(self.ps_value) + "ps\n"
return ret
def cal(self):
if self.flag == 1: #Hz
if self.unit == 1: #5Hz
self.Hz_value = float(self.value)
self.KHz_value = float(self.value / 1000)
self.MHz_value = float(self.value / 1000000)
self.GHz_value = float(self.value / 1000000000)
self.THz_value = float(self.value / 1000000000000)
elif self.unit == 3:
self.Hz_value = float(self.value * 1000)
self.KHz_value = float(self.value)
self.MHz_value = float(self.value / 1000)
self.GHz_value = float(self.value / 1000000)
self.THz_value = float(self.value / 1000000000)
elif self.unit == 6:
self.Hz_value = float(self.value * 1000000)
self.KHz_value = float(self.value * 1000)
self.MHz_value = float(self.value)
self.GHz_value = float(self.value / 1000)
self.THz_value = float(self.value / 1000000)
elif self.unit == 9:
self.Hz_value = float(self.value * 1000000000)
self.KHz_value = float(self.value * 1000000)
self.MHz_value = float(self.value * 1000)
self.GHz_value = float(self.value)
self.THz_value = float(self.value / 1000)
else:
self.Hz_value = float(self.value * 1000000000000)
self.KHz_value = float(self.value * 1000000000)
self.MHz_value = float(self.value * 1000000)
self.GHz_value = float(self.value * 1000)
self.THz_value = float(self.value)
self.s_value = float(1 / self.Hz_value)
self.ms_value = float(1 / self.KHz_value)
self.us_value = float(1 / self.MHz_value)
self.ns_value = float(1 / self.GHz_value)
self.ps_value = float(1 / self.THz_value)
else: #s
if self.unit == 1: #5s
self.s_value = float(self.value)
self.ms_value = float(self.value * 1000)
self.us_value = float(self.value * 1000000)
self.ns_value = float(self.value * 1000000000)
self.ps_value = float(self.value * 1000000000000)
elif self.unit == 3: #5ms
self.s_value = float(self.value / 1000)
self.ms_value = float(self.value )
self.us_value = float(self.value * 1000)
self.ns_value = float(self.value * 1000000)
self.ps_value = float(self.value * 1000000000)
elif self.unit == 6: #5us
self.s_value = float(self.value / 1000000)
self.ms_value = float(self.value / 1000)
self.us_value = float(self.value )
self.ns_value = float(self.value * 1000)
self.ps_value = float(self.value * 1000000)
elif self.unit == 9: #5ns
self.s_value = float(self.value / 1000000000)
self.ms_value = float(self.value / 1000000)
self.us_value = float(self.value / 1000)
self.ns_value = float(self.value)
self.ps_value = float(self.value * 1000)
elif self.unit == 12: #5ps
self.s_value = float(self.value / 1000000000000)
self.ms_value = float(self.value / 1000000000)
self.us_value = float(self.value / 1000000)
self.ns_value = float(self.value / 1000)
self.ps_value = float(self.value)
self.Hz_value = float(1 / self.s_value)
self.KHz_value = float(1 / self.ms_value)
self.MHz_value = float(1 / self.us_value)
self.GHz_value = float(1 / self.ns_value)
self.THz_value = float(1 / self.ps_value)
def prt(self):
ret = "Frequency:\n"
ret += " " + str(self.Hz_value) + " Hz\n"
ret += " " + str(self.KHz_value) + " KHz\n"
ret += " " + str(self.MHz_value) + " MHz\n"
ret += " " + str(self.GHz_value) + " GHz\n"
ret += " " + str(self.THz_value) + " THz\n"
ret += "\n"
ret += "Period:\n"
ret += " " + str(self.s_value) + " s\n"
ret += " " + str(self.ms_value) + " ms\n"
ret += " " + str(self.us_value) + " us\n"
ret += " " + str(self.ns_value) + " ns\n"
ret += " " + str(self.ps_value) + " ps\n"
return ret
pass
def input_proc(clk):
input = clk
res = re.match(r"([\d\.]+)\s*(\w+)", input)
if res:
value = res.group(1)
tmp = res.group(2)
unit = 9
flag = 1
if tmp.find("M") >= 0:
unit = 6
flag = 1 #频率,如900MHz
elif tmp.find("G") >= 0:
unit = 9
flag = 1
elif tmp.find("T") >= 0:
unit = 12
flag = 1
elif tmp.find("K") >= 0:
unit = 3
flag = 1
elif tmp.find("Hz") >= 0:
unit = 1
flag = 1
elif tmp.find("n") >= 0:
unit = 9
flag = 0 #周期,如5ns
elif tmp.find("m") >= 0:
unit = 3
flag = 0
elif tmp.find("u") >= 0:
unit = 6
flag = 0
elif tmp.find("p") >= 0:
unit = 12
flag = 0
elif tmp.find("s") >= 0:
unit = 1
flag = 0
else:
sys.exit(0)
return CLK(value, unit, flag)
pass
def tk_main():
def update_input():
input = e1.get()
clk = input_proc(input)
clk.cal()
ret = clk.prt()
text3.delete(0.0, END)
text3.insert(END, ret)
root = Tk()
root.geometry("400x280")
root.title("懒人时钟计算")
f1 = Frame(root, height = 40, width = 500)
l1 = Label(f1, text="输入时钟参数")
l1.pack(side = LEFT)
e1 = Entry(f1, bd =10, text="100M")
e1.pack(side = RIGHT)
f1.pack()
f2 = Frame(root, height = 40, width = 500)
f2.pack()
text3 = Text(f2, height = 15, undo=True, autoseparators=False)
text3.pack(side = RIGHT)
f3 = Frame(root, height = 10, width = 500)
f3.pack()
button2 = Button(f3, text='确定', command=update_input)
button2.pack(side=LEFT)
button3 = Button(f3, text='退出', command=root.quit)
button3.pack(side=LEFT)
root.mainloop()
def main():
tk_main()
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。