0
import sys
from PyQt4.QtCore import SIGNAL
from PyQt4.QtGui import QDialog, QApplication, QPushButton, QLineEdit, QFormLayout

class Form(QDialog):
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)

        self.le = QLineEdit()
        self.le.setText("Host")

        self.pb = QPushButton()

        self.pb.setText("Connect") 

        layout = QFormLayout()
        layout.addWidget(self.le)
        layout.addWidget(self.pb)

        self.setLayout(layout)
        self.connect(self.pb, SIGNAL("clicked()"),self.button_click)
        self.setWindowTitle("Learning")

    def button_click(self):
        # shost is a QString object
        shost = self.le.text()
        #what should I write here to access the other python file and give shost as input string to that file


app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()

Now when I enter text in lineedit and click connect pushbutton it should give the text as input to other python file which is given below. I need to modify the button_click(self) function in the above code so that it gives text in lineedit as input to the below python file.

 # Requiredfile.py
Enteredstring = input('Enter string:')
print Enteredstring
user1994124
  • 53
  • 1
  • 4

1 Answers1

0

considering your pyqt code is correct,

import sys
from PyQt4.QtCore import SIGNAL
from PyQt4.QtGui import QDialog, QApplication, QPushButton, QLineEdit, QFormLayout

class Form(QDialog):
  def __init__(self, parent=None):
    super(Form, self).__init__(parent)

    self.le = QLineEdit()
    self.le.setText("Host")

    self.pb = QPushButton()

    self.pb.setText("Connect") 

    layout = QFormLayout()
    layout.addWidget(self.le)
    layout.addWidget(self.pb)

    self.setLayout(layout)
    self.connect(self.pb, SIGNAL("clicked()"),self.button_click)
    self.setWindowTitle("Learning")

  def button_click(self):
    # shost is a QString object
    shost = self.le.text()
    import Requiredfile.py
    Requiredfile.func(shost)


app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()

you make a function named func in your requiredfile.py and import Requiredfile.py in your gui file and pass the shost var to the file.

here's your Requiredfile.py

def func(shost):
    Enteredstring = input('Enter string:')
    print Enteredstring
    print shost

so here you get the shost in your Requiredfile.py, do whatever you want to do with shost

scottydelta
  • 1,786
  • 4
  • 19
  • 39