Python Forum

Full Version: Crashing When Request Math Equation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
this error occurs when I click on Hpa- In i have no idea what is happening.
this error is occurring inline 68-70. thanks in advanced!

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import*
import sys


class mywindow(QMainWindow):
    def __init__(self):
        super(mywindow, self).__init__()
        self.setGeometry(0, 0, 700, 960)
        self.setWindowTitle('Electronic Flight Bag')
        self.initUI()


    def initUI(self):
        #webpage
        self.simbreif = QtWidgets.QPushButton(self)
        self.simbreif.setGeometry(510, 260, 171, 61)
        self.simbreif.setText('Open SimBrief')
        self.simbreif.clicked.connect(self.simbriefclick)

        self.skyvector = QtWidgets.QPushButton(self)
        self.skyvector.setGeometry(50, 600, 171, 61)
        self.skyvector.setText('SkyVector')
        self.skyvector.clicked.connect(self.skyvectorclick)

#        self.navigraph = QtWidgets.QCheckBox(self)
#        self.navigraph.setGeometry(520, 400, 91, 21)
#        self.navigraph.setText('navigraph')
#        self.navigraph.clicked.connect(self.chartclick)

        #math
        #hascopascels to inches of mercury
        self.hpain = QtWidgets.QPushButton(self)
        self.hpain.setGeometry(598,90,85,61)
        self.hpain.setText('Hpa - IN')
        self.hpain.clicked.connect(self.hpainclick)
        #label
        self.hpainlabel = QtWidgets.QLabel(self)
        self.hpainlabel.setText('21211')
        self.hpainlabel.move(560,210)

        #inches of mercury to hascopascels
        self.inhpa = QtWidgets.QPushButton(self)
        self.inhpa.setGeometry(510,90,85,61)
        self.inhpa.setText('IN - Hpa')
        #Hpa In entry
        self.hpainentry = QLineEdit(self)
        self.hpainentry.setGeometry(510,170,171,31)
        self.hpainentry.setPlaceholderText('Please Enter Unit of Choice')




    def simbriefclick(self):
        print('yes')
        self.web = QWebEngineView()
        self.web.load(QUrl('https://www.simbrief.com/'))
        self.web.show()

    def skyvectorclick(self):
        self.web = QWebEngineView()
        self.web.load(QUrl('https://skyvector.com/'))
        self.web.show()

    def hpainclick(self):
        hpainanswer = int(hpainentry) /3386
        self.hpainlabel.setText(hpainanswer)
    




def window():
    app = QApplication(sys.argv)
    win = mywindow()
    win.show()
    sys.exit(app.exec_())
window()
Output:
NameError: name 'hpainentry' is not defined
try

    def hpainclick(self):
        hpainanswer = int(self.hpainentry.text()) / 3386
        self.hpainlabel.setText(str(hpainanswer))