我想在qt设计器中创建一个重量计算器,我想在上面添加一些功能,但是我不能,请检查一下。
这是我的主页用户界面代码:我的ui文件:google link
import sys
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QDialog
from PyQt5.uic import loadUi
class MainPage(QDialog):
def __init__(self):
super(MainPage, self).__init__()
loadUi('Homepage.ui', self)
self.pushButton.clicked.connect(self.retrieveText)
def takeText(self):
x = self.plainTextEdit_2.currentText()
self.textEdit.setText(x)
def retrieveText(self):
number=self.plainTextEdit.toPlainText()
number=float(number) * my below fuction
self.textEdit.setText(str(number))
app=QApplication(sys.argv)
widget=MainPage()
widget.show()
sys.exit(app.exec_())
并且我想在上面添加一些功能:
gender=input("If Man, please type M or if women type W: ")
heigh=int(input("Whats your heigh: "))
if(gender=="M"):
r=int(((heigh*4/2.54)-128)*0.453)
print("Your ideal weight: " + str(r))
elif(gender=="W"):
r=int(((heigh*3.5/2.54)-108)*0.453)
print("Your ideal weight: "+str(r))
用户在第一个文本框中输入性别(M或W),在第二个文本框中输入身高,当单击结果按钮时,我们可以在最后一个框中看到结果
是的,我找到了,这很简单:)
import sys
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QDialog
from PyQt5.uic import loadUi
class MainPage(QDialog):
def __init__(self):
super(MainPage, self).__init__()
loadUi('HomePage.ui', self)
self.pushButton.clicked.connect(self.takeText)
self.fillCombobox()
def fillCombobox(self):
gender = ["M", "W"]
self.comboBox.addItems(gender)
def takeText(self):
gender = self.comboBox.currentText()
heigh = int(self.plainTextEdit.toPlainText())
if gender == "M":
r = int(((heigh * 4 / 2.54) - 128) * 0.453)
elif gender == "W":
r = int(((heigh * 3.5 / 2.54) - 108) * 0.453)
self.textEdit.setText(str(r))
if __name__ == "__main__":
app=QApplication(sys.argv)
widget=MainPage()
widget.show()
sys.exit(app.exec_())