PyQt4编辑QLineEdit并保留文本

时间:2018-04-16 14:23:13

标签: python pyqt pyqt4

以下代码使用Button和LineEdit创建一个Widget:

import sys
from PyQt4.QtGui import QApplication, QMainWindow, QPushButton, QLineEdit, QLabel, QComboBox, QProgressBar, QFileDialog
from PyQt4.QtCore import QSize, pyqtSlot

class App(QMainWindow):

    def __init__(self):
        super(App, self).__init__()
        self.setGeometry(500, 300, 820, 350)
        self.setWindowTitle("Widget")
        self.initUI()

    def initUI(self):

        #Buttons
        btnposx = 30
        btnposy = 50


        leposx = 150
        leposy = btnposy

        self.le = QLineEdit(self)
        self.le.move(leposx,leposy)
        self.le.resize(630,26)

        self.btn = QPushButton('Save',self)
        self.btn.move(btnposx,btnposy)
        self.btn.clicked.connect(self.edit_le)


        self.show()

    def edit_le(self):
        self.le.setText('hello')



if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

进一步按下按钮,LineEdit充满了' hello'。有没有办法保持'你好'字符串,即使Widget被关闭了吗?

编辑:

感谢您提供dyllanesc的dublicate链接。不幸的是,此线程中提供的示例代码似乎不起作用。我为PyQt4改编了它,但它没有保存任何东西。我正在使用Spyder。

0 个答案:

没有答案