I've watched every tutorial but found no luck, even tho I've tried everything. I've actually made a successful program with a login and all validations using Tkinter but as soon as i switched to PyQt5 for better design and more widgets, it's all of a sudden so confusing. I am a beginner programmer but I know more than the basics. It's just PyQt5 is somehow confusing to me and my Ui files can't convert to py for some reason so i can't use Qt designer.
That leads to my question, how can i receive username and password after the user clicks login.I also want to clear user input but that isn't important to me right now.
Please help I've been stuck on this for three days. The window and line edit is shown but nothing is working.
import sys
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget, QLineEdit, QLabel
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QIcon, QPixmap
class MainWindow(QMainWindow):
def __init__(login):
QMainWindow.__init__(login)
login.setMinimumSize(QSize(300, 195 ))
login.setWindowTitle("Login Window")
login.setStyleSheet("QLabel {font: 12pt Calibri}")
loginbtn = QtWidgets.QPushButton('Login', login)
loginbtn.clicked.connect(login.loginMethod)
loginbtn.resize(80,30)
loginbtn.move(60, 150)
clearbtn = QtWidgets.QPushButton('Clear', login)
clearbtn.clicked.connect(login.loginMethod)
clearbtn.resize(70,30)
clearbtn.move(170, 150)
###############USERNAME##########
userLabel=QLabel(login)
userLabel.setText("Username: ")
userLabel.move(10,20)
userinput=QtWidgets.QLineEdit(login)
userinput.move(90,20)
userinput.resize(150,30)
userinput.setPlaceholderText(" username")
#########PASSWORD##############
passLabel=QLabel(login)
passLabel.setText("Password: ")
passLabel.move(10,60)
passinput=QtWidgets.QLineEdit(login)
passinput.move(90,60)
passinput.resize(150,30)
def loginMethod(login):
sender=login.sender()
if sender.text()=="Login":
print(userinput.text())
else:
sender.text.clear()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit( app.exec_() )