samedi 30 septembre 2017

By clicking a button, print some texts entered in QLineEdit when a checkbox is checked PyQt4

By clicking a button, I want to print some texts that is entered in QLineEdit when a checkbox is checked. My example codes are as below:

import sys
import PyQt4
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class Widget(QWidget):
    def __init__(self, parent= None):
        super(Widget, self).__init__(parent)
        layout = QGridLayout()

        self.setLayout(layout)

        self.checkBox = QCheckBox()
        layout.addWidget(self.checkBox, 0, 0)


        self.le = QLineEdit()
        layout.addWidget(self.le, 0, 1)

        self.btn = QPushButton('Run')
        layout.addWidget(self.btn, 0, 3)


class Func ():
    def __init__(self):
        a = Widget(self)

    def someFunc(self):
        ##print ()


app = QApplication(sys.argv)
widget = Widget()
widget.show()
app.exec_()

As you can see above, I want the button in "Widget" class to connect to "someFunc" method in "Func" class. Thus when some texts are entered in "self.le" as well as "checkBox" is checked, I want "someFunc" to print the texts entered in "self.le" by clicking the button. If the "checkbox" is not checked, clicking the button should not cause anything to happen even when some texts are entered.

If anyone knows how to solve it, pls let me know thanks!!




Aucun commentaire:

Enregistrer un commentaire