Hi,
I would like to know how I can access a QLineEdit widget in a UI file directly from Python.
I have read some examples on the Internet but, I can't get it to work.
This is what I have:
original *.ui file: propertyDialog.ui
extracted *.py file: propertyDialog.py
QLineEdit widget name on the ui: "input_PipeName"
The script I have so far is:
I would like to know how I can access a QLineEdit widget in a UI file directly from Python.
I have read some examples on the Internet but, I can't get it to work.
This is what I have:
original *.ui file: propertyDialog.ui
extracted *.py file: propertyDialog.py
QLineEdit widget name on the ui: "input_PipeName"
The script I have so far is:
from PyQt5 import QtCore, QtGui, QtWidgets from propertyDialog import Ui_Dialog class mainProgram(QtWidgets.QMainWindow, Ui_Dialog): def __init__(self, parent=None): self.cntPipe = 0 self.cntLiner = 0 self.cntCoating = 0 self.pipeproperty = {} self.coating = {} self.liner = {} super(mainProgram, self).__init__(parent) # self.calc = Calculations() self.setupUi(self) self.response_AddPipe.clicked.connect(self.add_pipe) def add_pipe(self): self.cntPipe +=1 self.cntLiner = 0 self.cntCoating = 0 self.pipeproperty[self.cntPipe]={} pipe_name = self.inputPipe_name.text() self.pipeproperty[self.cntPipe]["Name"] = pipe_name if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) nextGui = mainProgram() nextGui.show() sys.exit(app.exec_())With the error:
Error:"C:\Users\Usr\Desktop\Work Folder PPM\VirtualEnvironment\Scripts\python.exe" "C:/Users/Usr/Desktop/Work Folder PPM/VirtualEnvironment/Scripts/Total.py"
Traceback (most recent call last):
File "C:/Users/Usr/Desktop/Work Folder PPM/VirtualEnvironment/Scripts/Total.py", line 151, in <module>
nextGui = mainProgram()
File "C:/Users/Usr/Desktop/Work Folder PPM/VirtualEnvironment/Scripts/Total.py", line 15, in __init__
self.response_AddPipe.clicked.connect(self.add_pipe())
File "C:/Users/Usr/Desktop/Work Folder PPM/VirtualEnvironment/Scripts/Total.py", line 23, in add_pipe
pipe_name = self.inputPipe_name.text()
AttributeError: 'mainProgram' object has no attribute 'inputPipe_name'
Process finished with exit code 1
Can someone help me with this? It seems to fail on:pipe_name = self.inputPipe_name.text()