.
Once you have it in a variable, you can throw the whole power of python at it. I have tried to show how to do this in the simplest way possible. Note: This code shamelessly stolen from xpathevaluator. Lots of good pyqt4 sample code in there. Also might be helpful if you want to evaluate an xpath. But I'm not sure why you would want to do that.
import sys
#Load the widget
from PyQt4.QtGui import QWidget #This is a widget, not a window, and that makes a difference from PyQt4.uic import loadUiType #We need this to dynamically load the .ui file we created in qt designer from PyQt4.QtCore import pyqtSignature, Qt #Not sure what this signature thing is, but apparently it is great for buttons (signals/slots?) import sys
(form, formbase) = loadUiType('readinput.ui') #this is the .ui file we want to show
class readInputWidget(QWidget, form): #in this class, we load the window, and assign actions to the buttons
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setAttribute(Qt.WA_DeleteOnClose) #This doesn't seem to change anything if you delete it, but may be usefull for housekeeping self.setupUi(self) @pyqtSignature("on_exitButton_clicked()") def on_exitButton_clicked(self): self.close() @pyqtSignature("on_evalButton_clicked()") def on_evalButton_clicked(self): print 'This should echo our text:' userinput = self.inputBox1.text() #This is the fantastic line of code we were waiting for! Make sure you have an input box by that name, and specify that it is text print userinput
def main():
from PyQt4.QtGui import QApplication from PyQt4.QtCore import Qt app = QApplication(sys.argv) widget = readInputWidget() widget.show() return app.exec_()
if __name__ == "__main__":
sys.exit(main())
You will also need the ui file that goes along with that.