1 Star 1 Fork 1

付明哲/单位转换器

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.py 2.86 KB
一键复制 编辑 原始数据 按行查看 历史
付明哲 提交于 2023-03-26 13:07 . main
from PySide6.QtWidgets import QApplication, QWidget
from Ui_Converter import Ui_Form
class CoverterWindow(QWidget, Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.lengthVar = {
"米": 100, "厘米": 1, "分米": 10, "千米": 100000, "里": 50000, "毫米": 0.1, "微米": 0.0001, "纳米": 0.0000001
}
self.weightVar = {
"千克": 1000, "克": 1, "斤": 500, "吨": 1000000, "毫克": 0.001, "微克": 0.000001
}
self.timeVar = {
"秒": 1/60, "分钟": 1, "小时": 60, "天": 24*60, "周": 24*60*7, "毫秒": 1/60000
}
self.velocityVar = {
"米/秒": 3.6, "公里/小时": 1
}
self.areaVar = {
"平方米": 10000, "平方厘米": 1, "平方分米": 100, "平方毫米": 0.01,"公顷": 100000000, "平方千米": 10000000000
}
self.volumeVar = {
"立方米": 1000000, "立方厘米": 1, "立方分米": 1000, "升": 1000, "立方毫米": 0.001, "立方千米": 1000000000000000
}
self.frequencyVar = {
"赫兹": 1, "毫赫": 0.001, "千赫兹": 1000, "微毫赫": 0.000001, "兆赫": 1000000, "千兆赫": 1000000000
}
self.TypeDict = {
"长度": self.lengthVar,
"质量": self.weightVar,
"时间": self.timeVar,
"速度": self.velocityVar,
"面积": self.areaVar,
"体积": self.volumeVar,
"频率": self.frequencyVar
}
self.dataTypeComboBox.addItems(self.TypeDict.keys())
self.oneComboBox.addItems(self.lengthVar.keys())
self.twoComboBox.addItems(self.lengthVar.keys())
self.oneInputEditLine.setText("1")
self.calc()
self.bind()
def bind(self):
self.dataTypeComboBox.currentTextChanged.connect(self.typeChanged)
self.pushButton.clicked.connect(self.calc)
def calc(self):
bigType = self.dataTypeComboBox.currentText()
value = self.oneInputEditLine.text()
if value == '':
return
currentType = self.oneComboBox.currentText()
transType = self.twoComboBox.currentText()
standardization = float(value) * self.TypeDict[bigType][currentType]
result = standardization / self.TypeDict[bigType][transType]
self.originNumLabel.setText(f'{value} {currentType} =')
self.transNumLabel.setText(f'{result} {transType}')
self.twoInputEditLine.setText(str(result))
def typeChanged(self, text):
self.oneComboBox.clear()
self.twoComboBox.clear()
self.oneComboBox.addItems(self.TypeDict[text].keys())
self.twoComboBox.addItems(self.TypeDict[text].keys())
self.calc()
if __name__ == "__main__":
app = QApplication([])
window = CoverterWindow()
window.show()
app.exec()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/fu-mingzhe/converter.git
[email protected]:fu-mingzhe/converter.git
fu-mingzhe
converter
单位转换器
master

搜索帮助