How to read from QTextedit in python?

前端 未结 2 998
长发绾君心
长发绾君心 2020-12-31 01:45

I created the GUI using QTDesigner and save the file as .ui extension. Then convert the file to .py file using the following code

pyuic4 -x test.ui -o test         


        
2条回答
  •  情深已故
    2020-12-31 02:06

    Along with the answer posted above. Don't modify the actual .py that is converted when you use pyuic4. You want to incorporate a class to handle the setup so that you can modify the UI without erasing everything that you have written. Example in pyqt5

    from MyConvertedUiFile import Ui_SomeName
    
    class MyWorkingCode(QtWidgets.QMainWindow, Ui_SomeName):
        def __init__(self, parent=None):
            super(MainWindow, self).__init__(parent)
            self.setupUi(self)
            self.pushButton.clicked.connect(self.ent)
    
        def ent(self):
            mytext = self.textEdit.toPlainText()
            with open('somefile.txt', 'a') as f:
                f.write(mytext)
    

    This should be how you utilize the converted Ui files it will make it so you can re edit the file and you wont loose all of the work you have put into the Ui control structure. It will also allow you to use the same Ui for multiple purposes as you are using it as a template and changing what the buttons do in a different file. Hope this helps.

提交回复
热议问题