如何将一个文件的输出作为其他文件的输入,如何将pyqt4中LineEdit中输入的文本作为输入字符串提供给另一个文件

2024-09-29 02:15:24 发布

您现在位置:Python中文网/ 问答频道 /正文

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_()

当我在下面输入文本时,点击下面的文本输入。我需要修改上面代码中的button_click(self)函数,以便它将lineedit中的文本作为以下python文件的输入。在

^{pr2}$

Tags: from文本importselfformlesignalsys
1条回答
网友
1楼 · 发布于 2024-09-29 02:15:24

考虑到你的pyqt代码是正确的

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_()

在所需文件.py进口和进口所需文件.py并将shost变量传递给该文件。在

这是你的所需文件.py在

^{pr2}$

所以在这里你得到了所需文件.py,对shost做任何你想做的事

相关问题 更多 >