-1

I have the following code in one python file (sales.py) and want to display the results of the script's calculation in a QLineEdit of a separate file (control.py).

All line_edit.setText(def), line_edit.dispayText(def), line_edit.setText(subtotal) are not working. Any ideas of how I could go about doing this?

Thanks in advance for any suggestions.

#sales py

def main () :
    total()

def total () :

    totals = { "quantity" : 4 , "price" : 1.5}

    total_quant = totals [ "quantity" ]
    total_price = totals [ "price" ]

    subtotal = str(total_quant * total_price)

    return subtotal


 main()

--------------

#the below is not working
#controls.py

from sales import *
import sys
from PyQt4 import QtGui, QtCore

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()

        self.initUI()


    def initUI(self): 

       q_le = QtGui.QLineEdit(self)
       q_le.move (50,50)
       q_le.setText(total())

       self.setGeometry(300, 300, 250, 150)
       self.setWindowTitle('Line Edit')    
       self.show()

def main():

    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
rainer
  • 3,295
  • 5
  • 34
  • 50
  • This code is so fragmentary that it's not obvious how to even start to fix it. But two immediate problems stand out. `subtotal` is local to the `total` function and cannot be imported. `line_edit` is never defined. You seem to be trying to use PyQT but without calling it at all? – strubbly Sep 08 '16 at 14:50
  • strubbty: thanks for the time to analyze this and sorry for the inconvenience of the fragmented code. See above for the improvements. Want I intend is get the value from one file and display it in the lineedit of the other file. – rainer Sep 09 '16 at 17:08
  • You need to post full error messages. Your `initUI(self)` method is using a `total` variable that is *undefined*. Perhaps you meant to invoke the function `total()` instead (i.e. `q_le.setText(sales.total())`)? – code_dredd Sep 09 '16 at 17:19
  • Hi Ray. Thanks for you effort. I have tried your suggestion (corrected above), but I now get the error message: (line edit .. ) argument 1 has unexpected type 'NoneType'. Any hint of how I can get rid of that? Thanks in advance. – rainer Sep 10 '16 at 19:18
  • 1
    Well your `total()` function does not actually return anything, so you might want to fix that. – UnholySheep Sep 10 '16 at 19:22
  • great, that worked ... thanks a lot .... the script above is already updated ... – rainer Sep 10 '16 at 23:11

1 Answers1

0

At the beginning I had my doubts that what I had in mind - get a script result from one py file and display it in a QLineEdit of another py file - would ever work. With the help of more experienced developers the solution turned out to be actually quite easy.

In fact, my inquiries are part of a personal learning project, that is, subdivide a large script into smaller portions, saved in separate files.

I have updated the code already, in case others are facing similar issues.

rainer
  • 3,295
  • 5
  • 34
  • 50