0

UPDATE I made a function to get the text from QLineEdit in the logingui file, and it works. I have no idea why the same function wouldn't work if imported from a different file.

I am trying to get text from QLineEdit on a button click, I have 2 files, logingui and loginlogic. Both the files import each other. Here's the logingui's code

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import login.loginlogic

class LoginForm(QWidget):

    def __init__(self):
        QWidget.__init__(self, parent=None)

        object = login.loginlogic


        formLayout = QFormLayout()
        # vboxlayout = QVBoxLayout()

        serifFont = QFont("Arial", 10)

        unamelbl = QLabel("Username")
        unamelbl.setFont(serifFont)
        pwdlbl = QLabel("Password")
        pwdlbl.setFont(serifFont)

        self.unamele = QLineEdit()
        self.pwdle = QLineEdit()

        self.unamele.setPlaceholderText("Username")
        self.pwdle.setPlaceholderText("Password")

        self.loginButton = QPushButton("Login")

        self.loginButton.setStyleSheet("background-color: #99ff99; font-size: 15px;")
        self.loginButton.setFont(serifFont)
        self.loginButton.clicked.connect(object.handleLogin)

        formLayout.addRow(unamelbl)
        formLayout.addRow(self.unamele)
        formLayout.addRow(pwdlbl)
        formLayout.addRow(self.pwdle)
        formLayout.addRow(self.loginButton)

        formLayout.setSpacing(20)

        self.setLayout(formLayout)
        self.setStyleSheet("background-color: rgb(255,255,255)")
        self.setMinimumSize(420, 320)
        self.setMaximumSize(420, 320)
        self.setContentsMargins(60, 50, 60, 50)
        self.setWindowIcon(QIcon("favicon.ico"))
        self.show()

    def handlelogin(self):
        u = self.unamele.text()
        print(u)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    form = LoginForm()
    app.exec_()

here's the code from loginlogic

import login.logingui


class handleLogin():
    def __init__(self):
        self.obj = login.logingui.LoginForm()
        self.username = self.obj.unamele.text()
        print("the code did reach here my man ")
        print(self.username)



if __name__ == '__main__':
    a = handleLogin()

now the output that I get is

your code reached here
*blank line*

I know that's a blank line cause when I click the button again it just leaves an empty line and the reached here text again. Also when I run the logingui, I do write some text in it. Not leaving it blank.

Sahil
  • 1,387
  • 14
  • 41

0 Answers0