Home>

I have a window where I enter the product data. There is a button that opens a small window with counting all the items that we entered. The small window displays the name of the product, the weight of the product and its price.

Trying to withdraw the amount, for example, the mass of the product -I get an error that Pajton cannot translate String in float. Or I do something wrong.

Tell me how to properly convey all the values ​​to another window? It is also interesting as other elements to transfer to another window.

Sample code:

from pyqt5.qtwidgets import (qpplication, qpushbutton, qwidget, qdialog,
                         QGridlayout, QLabel, Qlineedit)
From Pyqt5 Import Qtcore
from pyqt5.Qtgui import qicon
from pyqt5 import qtwidgets
from pyqt5.Qtcore import qt, qsize
Import sys.
Class CreateCalc (QWidget):
    Def __init __ (Self, Parent= None, ** kwargs):
        Super () .__ init __ (Parent, Qtcore.qt.Window, ** kwargs)
        Self.dialog= Dialog (Self)
        self.initui ()
    DEF INITUI (SELF):
        Self.Resize (250, 230)
        Self.setWindowicon (Qicon ('icon.png'))
        Self.setWindowTitle ('Create Calculation')
        Self.Grid= QGridlayout (Self)
        Self.prod= QLabel ('Name of Product:', Self)
        self.Prodedit= QLineEdit (SELF)
        Self.Prodedit.move (100, 8)
        Self.Prodedit.Resize (80, 20)
        Self.INGREDIENTS= QLabel ('Ingredients:', Self)
        Self.INGREDIENTS.Move (80, 20)
        self.edit1= QLineEdit (Self, maximumsize= qsize (80, 20))
        Self.Weight1= QLabel ('Weight:', Self)
        Self.Weight1.move (92, 42)
        self.edit2= QLineEdit (Self, maximumsize= qsize (35, 20))
        self.edit2.move (135, 49)
        self.cost1= QLabel ('COST:', SELF)
        self.cost1.move (176, 42)
        self.edit3= QLineEdit (Self, maximumsize= qsize (35, 20))
        self.edit3.move (205, 49)
        self.edit4= qlineedit (Self, maximumsize= qsize (80, 20))
        Self.Weight2= QLabel ('Weight:', Self)
        Self.Weight2.move (95, 68)
        self.edit5= QLineEdit (Self, MaximumSize= QSIZE (35, 20))
        self.edit5.move (135, 75)
        self.cost2= QLabel ('COST:', SELF)
        self.cost2.move (176, 68)
        self.edit6= QLineEdit (Self, MaximumSize= QSIZE (35, 20))
        self.edit6.move (205, 75)
        self.edit7= QLineEdit (Self, maximumsize= qsize (80, 20))
        Self.Weight3= QLabel ('Weight:', Self)
        Self.Weight3.move (95, 94)
        self.edit8= QLineEdit (Self, MaximumSize= QSIZE (35, 20))
        self.edit8.move (135, 101)
        Self.Cost3= QLabel ('COST:', SELF)
        self.cost3.move (176, 94)
        self.edit9= QLineEdit (Self, MaximumSize= QSIZE (35, 20))
        self.edit9.move (205, 101)
        self.edit10= QLineEdit (Self, maximumsize= QSIZE (80, 20))
        Self.Weight4= QLabel ('Weight:', Self)
        Self.Weight4.move (95, 120)
        self.edit11= QLineEdit (Self, maximumsize= qsize (35, 20))
        self.edit11.move (135, 127)
        Self.Cost4= QLabel ('COST:', SELF)
        Self.Cost4.move (176, 120)
        self.Edit12= QLineEdit (Self, MaximumSize= QSIZE (35, 20))
        self.Edit12.move (205, 127)
        self.edit13= QLineEdit (Self, MaximumSize= QSize (80, 20))
        Self.Weight5= QLabel ('Weight:', Self)
        Self.Weight5.move (95, 146)
        self.edit14= QLineEdit (Self, MaximumSize= QSIZE (35, 20))
        self.edit14.move (135, 153)
        self.cost5= QLabel ('COST:', SELF)
        self.cost5.move (176, 146)
        self.edit15= QLineEdit (Self, maximumsize= QSIZE (35, 20))
        self.edit15.move (205, 153)
        self.edit16= qlineedit (Self, maximumsize= qsize (80, 20))
        Self.Weight6= QLabel ('Weight:', Self)
        Self.Weight6.move (95, 172)
        self.edit17= QLineEdit (Self, MaximumSize= QSIZE (35, 20))self.edit17.move (135, 179) Self.Cost6= QLabel ('COST:', SELF)
        self.cost6.move (176, 172)
        self.edit18= qlineedit (Self, MaximumSize= QSIZE (35, 20))
        self.edit18.move (205, 179)
        Self.Button= QPushButton ('Calculate')
        self.button.clicalked.connect (Self.dialog.exec)
        self.button.clicked.connect (self.calculate)
        self.grid.addwidget (Self.prod, 0, 0, Alignment= Qt.alignleft)
        Self.Grid.Addwidget (self.ingredients, 1, 0, alignment= qt.alignleft)
        self.grid.addwidget (self.edit1, 2, 0, alignment= qt.alignleft)
        Self.Grid.addwidget (self.edit4, 3, 0, alignment= qt.alignleft)
        Self.Grid.addwidget (self.edit7, 4, 0, alignment= qt.alignleft)
        self.grid.addwidget (Self.Edit10, 5, 0, Alignment= Qt.alignleft)
        self.grid.addwidget (Self.Edit13, 6, 0, Alignment= Qt.alignleft)
        self.grid.addwidget (Self.Edit16, 7, 0, Alignment= Qt.alignleft)
        self.grid.addwidget (Self.Button, 8, 0, Alignment= Qt.alignCenter)
        Self.Grid.Setrowstretch (10, 1)
        # Self.Result= int (Float (Self.Edit2.Text () + self.edit5.text () +
    Self.Edit8.Text () + Self.Edit11.Text () + Self.Edit14.Text () +
   self.Edit17.Text ()))
    DEF CALCULATE (SELF):
        # Self.button.clicalked.connect (Self.Result)
        Self.Close ()
Class Dialog (QDialog):
    Def __init __ (Self, root, ** kwargs):
        Super () .__ Init __ (root, ** kwargs)
        Self.main= root.
        Self.setWindowTitle ('Result')
        Self.Resize (250, 100)
        # Self.cc= CreateCalc ()
        Self.namep= QLabel ('Name of Your Product:')
        self.nameed= QLineEdit ()
        Self.WeigLB= QLabel ('Weight of Your Product:')
        self.weiged= QLineEdit ()
        # Self.WeiGed.setText ()
        Self.CostLB= QLabel ('Cost of Your Products:')
        self.costed= QLineEdit ()
        Self.Butcl= QPushButton ('Close')
        self.Butcl.Clicked.connect (Self.Closew)
        Self.Grid= QGridlayout (Self)
        Self.Grid.Addwidget (self.namep, 0, 0, alignment= qt.alignleft)
        self.grid.addwidget (self.nameed, 0, 1, alignment= qt.alignright)
        self.grid.addwidget (Self.WeiglB, 1, 0, Alignment= Qt.alignleft)
        self.grid.addwidget (Self.weiged, 1, 1, alignment= qt.alignright)
        Self.Grid.Addwidget (self.costlb, 2, 0, alignment= qt.alignleft)
        self.grid.addwidget (self.costed, 2, 1, alignment= qt.alignright)
        self.grid.addwidget (Self.Butcl, 3, 1, Alignment= Qt.alignCenter)
        Self.Grid.Setrowstretch (5, 1)
    Def Closeew (Self):
        Self.Close ()
if __name__== '__main__':
    App= Qapplication (SYS.Argv)
    Window= CreateCalc ()
    Window.Show ()
    sys.exit (app.exec_ ())