加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
clk_dis.py 5.88 KB
一键复制 编辑 原始数据 按行查看 历史
尼德兰的喵 提交于 2022-06-07 11:23 . init
#-*-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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化