This question already has answers here:
QtDesigner changes will be lost after redesign User Interface
(2 answers)
How to close a QDialog
(4 answers)
Closed 1 year ago.
I've created a program that allows you to login and sign up. When you have the right credentials it opens a window but it doesn't close. The same thing happens when you press the button to sign up. I've tried to use the close method but it doesn't work i always get:
AttributeError: type object 'Ui_Dialog' has no attribute 'close'
here is the full code of all the windows:
Login Page
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QMessageBox
import sqlite3
from welcome import Ui_MainWindow
from signup_page import Ui_Dialog2
import sys
#widget.setCurrentIndex(widget.currentIndex)
class Ui_Dialog(object):
def showMessageBox(self):
font = QtGui.QFont()
font.setPointSize(20)
self.label.setFont(font)
self.label.setStyleSheet("color: rgb(0, 0, 0);\n"
"background-color: rgb(255, 0, 0);")
self.label.setObjectName("label")
self.label.setText("WRONG USERNAME/PASSWORD")
def loginCheck(self):
username = self.username_input.text()
password = self.password_input.text()
connection = sqlite3.connect("login.db")
result = connection.execute("SELECT * FROM USERS WHERE USERNAME = ? AND PASSWORD = ?", (username, password))
if (len(result.fetchall())) > 0:
self.welcomewindow = QtWidgets.QMainWindow()
self.ui = Ui_MainWindow()
self.ui.setupUi(self.welcomewindow)
self.welcomewindow.show()
else:
self.showMessageBox()
def singup(self):
self.signup_page = QtWidgets.QDialog()
self.ui = Ui_Dialog2()
self.ui.setupUi(self.signup_page)
self.signup_page.show()
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(591, 457)
self.user_name_label = QtWidgets.QLabel(Dialog)
self.user_name_label.setGeometry(QtCore.QRect(190, 150, 81, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.user_name_label.sizePolicy().hasHeightForWidth())
self.user_name_label.setSizePolicy(sizePolicy)
self.user_name_label.setSizeIncrement(QtCore.QSize(0, 0))
self.user_name_label.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(13)
self.user_name_label.setFont(font)
self.user_name_label.setObjectName("user_name_label")
self.password_label = QtWidgets.QLabel(Dialog)
self.password_label.setGeometry(QtCore.QRect(190, 210, 81, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.password_label.sizePolicy().hasHeightForWidth())
self.password_label.setSizePolicy(sizePolicy)
self.password_label.setSizeIncrement(QtCore.QSize(0, 0))
self.password_label.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(13)
self.password_label.setFont(font)
self.password_label.setObjectName("password_label")
self.username_input = QtWidgets.QLineEdit(Dialog)
self.username_input.setGeometry(QtCore.QRect(280, 150, 141, 20))
self.username_input.setObjectName("username_input")
self.password_input = QtWidgets.QLineEdit(Dialog)
self.password_input.setGeometry(QtCore.QRect(280, 210, 141, 20))
self.password_input.setObjectName("password_input")
self.password_input.setEchoMode(self.password_input.Password)
self.login_btn = QtWidgets.QPushButton(Dialog)
self.login_btn.setGeometry(QtCore.QRect(200, 260, 81, 31))
font = QtGui.QFont()
font.setPointSize(13)
self.login_btn.setFont(font)
self.login_btn.setObjectName("login_btn")
#########Button Event##########
self.login_btn.clicked.connect(self.loginCheck)
###############################
self.signup_btn = QtWidgets.QPushButton(Dialog)
self.signup_btn.setGeometry(QtCore.QRect(300, 260, 81, 31))
########Button Event##########
self.signup_btn.clicked.connect(self.singup)
##############################
font = QtGui.QFont()
font.setPointSize(13)
self.signup_btn.setFont(font)
self.signup_btn.setObjectName("signup_btn")
self.login_title = QtWidgets.QLabel(Dialog)
self.login_title.setGeometry(QtCore.QRect(240, 40, 91, 71))
font = QtGui.QFont()
font.setPointSize(20)
self.login_title.setFont(font)
self.login_title.setObjectName("login_title")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(130, 370, 391, 31))
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Login Page"))
self.user_name_label.setText(_translate("Dialog", "Username"))
self.password_label.setText(_translate("Dialog", "Password"))
self.login_btn.setText(_translate("Dialog", "Login"))
self.signup_btn.setText(_translate("Dialog", "Sign Up"))
self.login_title.setText(_translate("Dialog", " Login"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
widget = QtWidgets.QStackedWidget()
MainWindow = QtWidgets.QMainWindow()
ui = Ui_Dialog()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
The main window:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(593, 458)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(200, 180, 221, 71))
font = QtGui.QFont()
font.setPointSize(40)
self.label.setFont(font)
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "Welcome"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
and the signup page:
from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3
from welcome import Ui_MainWindow
import re
from PyQt5.QtWidgets import QMessageBox
class Ui_Dialog2(object):
def showMessageBox_password(self):
font = QtGui.QFont()
font.setPointSize(20)
self.label.setFont(font)
self.label.setStyleSheet("color: rgb(0, 0, 0);\n"
"background-color: rgb(255, 0, 0);")
self.label.setObjectName("label")
self.label.setText("INVALID PASSWORD")
def showMessageBox_email(self):
font = QtGui.QFont()
font.setPointSize(20)
self.label.setFont(font)
self.label.setStyleSheet("color: rgb(0, 0, 0);\n"
"background-color: rgb(255, 0, 0);")
self.label.setObjectName("label")
self.label.setText(" INVALID EMAIL")
def insertData(self):
username = self.username_entry.text()
password = self.password_entry.text()
email = self.email_entry.text()
connection = sqlite3.connect("login.db")
regex = '^(\w|\.|\_|\-)+[#](\w|\_|\-|\.)+[.]\w{2,3}$'
valid_email = True
valid_password = True
if(re.search(regex, email)):
valid_email = True
else:
valid_email = False
if len(password) > 7:
valid_password = True
else:
valid_password = False
if valid_email == True and valid_password == True:
connection.execute("INSERT INTO USERS VALUES(?,?,?)", (username, email, password))
connection.commit()
self.welcomewindow = QtWidgets.QMainWindow()
self.ui = Ui_MainWindow()
self.ui.setupUi(self.welcomewindow)
self.welcomewindow.show()
if valid_email == False:
self.showMessageBox_email()
elif valid_password == False:
self.showMessageBox_password()
connection.close()
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(593, 458)
self.user_name_label = QtWidgets.QLabel(Dialog)
self.user_name_label.setGeometry(QtCore.QRect(190, 200, 81, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.user_name_label.sizePolicy().hasHeightForWidth())
self.user_name_label.setSizePolicy(sizePolicy)
self.user_name_label.setSizeIncrement(QtCore.QSize(0, 0))
self.user_name_label.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(13)
self.user_name_label.setFont(font)
self.user_name_label.setObjectName("user_name_label")
self.password_label = QtWidgets.QLabel(Dialog)
self.password_label.setGeometry(QtCore.QRect(190, 240, 81, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.password_label.sizePolicy().hasHeightForWidth())
self.password_label.setSizePolicy(sizePolicy)
self.password_label.setSizeIncrement(QtCore.QSize(0, 0))
self.password_label.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(13)
self.password_label.setFont(font)
self.password_label.setObjectName("password_label")
self.email_label = QtWidgets.QLabel(Dialog)
self.email_label.setGeometry(QtCore.QRect(190, 160, 81, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.email_label.sizePolicy().hasHeightForWidth())
self.email_label.setSizePolicy(sizePolicy)
self.email_label.setSizeIncrement(QtCore.QSize(0, 0))
self.email_label.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(13)
self.email_label.setFont(font)
self.email_label.setObjectName("email_label")
self.email_entry = QtWidgets.QLineEdit(Dialog)
self.email_entry.setGeometry(QtCore.QRect(270, 160, 200, 20))
self.email_entry.setObjectName("email_entry")
self.username_entry = QtWidgets.QLineEdit(Dialog)
self.username_entry.setGeometry(QtCore.QRect(270, 200, 200, 20))
self.username_entry.setObjectName("username_entry")
self.password_entry = QtWidgets.QLineEdit(Dialog)
self.password_entry.setGeometry(QtCore.QRect(270, 240, 200, 20))
self.password_entry.setObjectName("password_entry")
self.password_entry.setEchoMode(self.password_entry.Password)
self.sign_up_button = QtWidgets.QPushButton(Dialog)
self.sign_up_button.setGeometry(QtCore.QRect(270, 280, 81, 31))
font = QtGui.QFont()
font.setPointSize(13)
self.sign_up_button.setFont(font)
self.sign_up_button.setObjectName("sign_up_button")
self.sign_up_button.clicked.connect(self.insertData)
self.login_title = QtWidgets.QLabel(Dialog)
self.login_title.setGeometry(QtCore.QRect(220, 50, 191, 71))
font = QtGui.QFont()
font.setPointSize(20)
self.login_title.setFont(font)
self.login_title.setObjectName("login_title")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(170, 360, 251, 31))
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Sign Up Page"))
self.user_name_label.setText(_translate("Dialog", "Username"))
self.password_label.setText(_translate("Dialog", "Password"))
self.email_label.setText(_translate("Dialog", "Email"))
self.sign_up_button.setText(_translate("Dialog", "Sign Up"))
self.login_title.setText(_translate("Dialog", "Create Account"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_Dialog2()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Related
from PyQt5 import QtCore, QtGui, QtWidgets
import password_checker
import pyperclip
from PyQt5.QtCore import pyqtSignal, QEvent,QObject
from PyQt5.QtWidgets import QPushButton
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(890, 651)
#NEW
MainWindow.setFixedSize(890, 651)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.bg = QtWidgets.QLabel(self.centralwidget)
self.bg.setGeometry(QtCore.QRect(0, 0, 890, 651))
self.bg.setObjectName("bg")
path = 'C:/Users/cheik/OneDrive/Desktop/WORK/pass/main/bg.jpeg'
self.bg.setPixmap(QtGui.QPixmap(path))
self.bg.setScaledContents(True)
self.button1 = QtWidgets.QPushButton(self.centralwidget)
self.button1.setGeometry(QtCore.QRect(20, 300, 121, 51))
self.button1.setObjectName("button1")
#NEW
self.button2 = QtWidgets.QPushButton(self.centralwidget)
self.button2.setGeometry(QtCore.QRect(750, 300, 100, 51))
self.button2.setObjectName("button2")
self.button3 = QtWidgets.QPushButton(self.centralwidget)
self.button3.setGeometry(QtCore.QRect(170, 300, 121, 51))
self.button3.setObjectName("button3")
self.label1 = QtWidgets.QLabel(self.centralwidget)
self.label1.setGeometry(QtCore.QRect(40, 210, 231, 51))
font = QtGui.QFont()
font.setPointSize(12)
font.setFamily('arial')
self.label1.setFont(font)
self.label1.setObjectName("label1")
self.header = QtWidgets.QLabel(self.centralwidget)
self.header.setGeometry(QtCore.QRect(100, 0, 701, 91))
font = QtGui.QFont()
font.setPointSize(20)
font.setFamily('arial')
self.header.setFont(font)
self.header.setObjectName("header")
self.label2 = QtWidgets.QLabel(self.centralwidget)
self.label2.setGeometry(QtCore.QRect(590, 210, 231, 51))
font = QtGui.QFont()
font.setPointSize(12)
font.setFamily('arial')
self.label2.setFont(font)
self.label2.setObjectName("label2")
self.text1 = QtWidgets.QLineEdit(self.centralwidget)
self.text1.setGeometry(QtCore.QRect(550, 300, 200, 51))
self.text1.setObjectName("text1")
self.output = QtWidgets.QLabel(self.centralwidget)
self.output.setGeometry(QtCore.QRect(90, 390, 701, 91))
font = QtGui.QFont()
font.setPointSize(20)
font.setFamily('arial')
self.output.setFont(font)
self.output.setObjectName("output")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 890, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
#NEW
self.button1.clicked.connect(self.passGen)
self.button2.clicked.connect(self.passCheck)
self.button3.clicked.connect(self.passGen2)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Pass Generator/Checker"))
self.button1.setText(_translate("MainWindow", "Basic"))
self.label1.setText(_translate("MainWindow", "Generate New Password"))
self.header.setText(_translate("MainWindow", "Welcome to the password generator/checker!"))
self.label2.setText(_translate("MainWindow", "Check Password Strength"))
#NEW
self.output.setText(_translate("MainWindow", ""))
self.button2.setText(_translate("MainWindow", "ENTER"))
self.button3.setText(_translate("MainWindow", "Advanced"))
#NEW
def passGen(self):
newPass = password_checker.passGen()
self.output.setText(newPass)
self.output.adjustSize()
self.output.move(320, 400)
msg = QtWidgets.QMessageBox()
msg.setStyleSheet("color:black;background:white}")
msg.setText(newPass + "\nHas been copied to clipboard")
msg.setWindowTitle("Copy")
msg.move(520,600)
msg.exec()
pyperclip.copy(newPass)
def passGen2(self):
newPass = password_checker.passGen2()
self.output.setText(newPass)
self.output.adjustSize()
self.output.move(320, 400)
msg = QtWidgets.QMessageBox()
msg.setStyleSheet("color:black;background:white}")
msg.setText(newPass + "\nHas been copied to clipboard")
msg.setWindowTitle("Copy")
msg.move(520,600)
msg.exec()
pyperclip.copy(newPass)
#NEW
def passCheck(self):
text = self.text1.text()
val = ""
if len(text) == 0:
self.output.setText("Please Enter Something!")
self.output.adjustSize()
self.output.move(270, 400)
else:
val = password_checker.passCheck(text)
self.output.setText(val)
self.output.adjustSize()
self.output.move(270, 400)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
#NEW
app.setStyleSheet('QPushButton {background-color: black; color: white;} QLabel {color: white;}')
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
I have a python app that change mac address with pyqt5 GUI. I have two python files. The main python file (mainWindow.py) that run main program then I press button to open the second window from second python file secondWindow.py. In second python file opens a window entry then I have to put letters and numbers like then I have to pass data in the first main app label window.
Can anyone help me to solve that?
I tried to reduce code.
mainWindow.py
#!/usr/bin/python3
import os
import sys
import subprocess
from PyQt5 import QtCore, QtGui, QtWidgets
from secondWindow import Ui_macSpecific
import macspoof_bash
import settings
macspoof_bash.write_to_ini()
# Read and write settings in macspoof.ini file
from configparser import ConfigParser
# instantiate
config = ConfigParser()
# parse existing file
config.read('/home/user/.config/macspoof/macspoof.ini')
# read values from a section
wired = config.get('ethernet', 'wired')
wireless = config.get('wifi', 'wireless')
class Ui_MainWindow(object):
def specificWindow(self):
self.window = QtWidgets.QDialog()
self.ui = Ui_macSpecific()
#self.ui.setupUi(self.window)
self.ui.setupUi(self.window, self) # <--- assign MainWindow as parent to second window
self.window.show()
def aboutWindow(self):
self.aboutWindow = QtWidgets.QDialog()
self.ui = Ui_Dialog()
self.ui.setupUi(self.aboutWindow)
self.aboutWindow.show()
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(480, 400)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setStyleSheet("background-color: rgb(36, 31, 49);\n"
"font: 11pt \"DejaVu Sans\";\n"
"color: rgb(246, 245, 244);")
self.label_3.setAlignment(QtCore.Qt.AlignCenter)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1)
self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.specificWindow())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_6.sizePolicy().hasHeightForWidth())
self.pushButton_6.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_6.setFont(font)
self.pushButton_6.setObjectName("pushButton_6")
self.gridLayout.addWidget(self.pushButton_6, 4, 1, 1, 1)
self.pushButton = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_vendor_wired())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.gridLayout.addWidget(self.pushButton, 2, 0, 1, 1)
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_fully_wired())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth())
self.pushButton_3.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_3.setFont(font)
self.pushButton_3.setObjectName("pushButton_3")
self.gridLayout.addWidget(self.pushButton_3, 3, 0, 1, 1)
self.pushButton_8 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_original_wireless())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_8.sizePolicy().hasHeightForWidth())
self.pushButton_8.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_8.setFont(font)
self.pushButton_8.setLayoutDirection(QtCore.Qt.LeftToRight)
self.pushButton_8.setAutoFillBackground(False)
self.pushButton_8.setObjectName("pushButton_8")
self.gridLayout.addWidget(self.pushButton_8, 5, 1, 1, 1)
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_vendor_wireless())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_2.sizePolicy().hasHeightForWidth())
self.pushButton_2.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.gridLayout.addWidget(self.pushButton_2, 2, 1, 1, 1)
self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_original_wired())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_7.sizePolicy().hasHeightForWidth())
self.pushButton_7.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_7.setFont(font)
self.pushButton_7.setObjectName("pushButton_7")
self.gridLayout.addWidget(self.pushButton_7, 5, 0, 1, 1)
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.specificWindow())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_5.sizePolicy().hasHeightForWidth())
self.pushButton_5.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_5.setFont(font)
self.pushButton_5.setObjectName("pushButton_5")
self.gridLayout.addWidget(self.pushButton_5, 4, 0, 1, 1)
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setStyleSheet("background-color: rgb(36, 31, 49);\n"
"font: 11pt \"DejaVu Sans\";\n"
"color: rgb(246, 245, 244);")
self.label_4.setObjectName("label_4")
self.label_4.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.label_4, 1, 1, 1, 1)
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: self.button_fully_wireless())
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_4.sizePolicy().hasHeightForWidth())
self.pushButton_4.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.pushButton_4.setFont(font)
self.pushButton_4.setObjectName("pushButton_4")
self.gridLayout.addWidget(self.pushButton_4, 3, 1, 1, 1)
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setMinimumSize(QtCore.QSize(0, 0))
self.label.setSizeIncrement(QtCore.QSize(0, 0))
self.label.setStyleSheet("background-color: rgb(36, 31, 49);\n"
"font: 11pt \"DejaVu Sans\";\n"
"color: rgb(246, 245, 244);")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setStyleSheet("background-color: rgb(36, 31, 49);\n"
"font: 11pt \"DejaVu Sans\";\n"
"color: rgb(246, 245, 244);")
self.label_2.setObjectName("label_2")
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.label_2, 0, 1, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 480, 20))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
self.menuEdit = QtWidgets.QMenu(self.menubar)
self.menuEdit.setObjectName("menuEdit")
self.menuHelp = QtWidgets.QMenu(self.menubar)
self.menuHelp.setObjectName("menuHelp")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionExit = QtWidgets.QAction(MainWindow)
self.actionExit.triggered.connect(lambda: self.close_window())
self.actionExit.setObjectName("actionExit")
self.actionPreferences = QtWidgets.QAction(MainWindow)
self.actionPreferences.setObjectName("actionPreferences")
self.actionAbout = QtWidgets.QAction(MainWindow)
self.actionAbout.triggered.connect(lambda: self.aboutWindow())
self.actionAbout.setObjectName("actionAbout")
self.menuFile.addAction(self.actionExit)
self.menuEdit.addAction(self.actionPreferences)
self.menuHelp.addAction(self.actionAbout)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuEdit.menuAction())
self.menubar.addAction(self.menuHelp.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.update_wired_label(MainWindow)
self.update_wired_mac_address_label(MainWindow)
self.update_wireless_label(MainWindow)
self.update_wireless_mac_address_label(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MAC address spoofing"))
self.label_3.setText(_translate("MainWindow", "TextLabel"))
self.pushButton_6.setText(_translate("MainWindow", "Set the MAC"))
self.pushButton.setText(_translate("MainWindow", "Don\'t change vendor bytes"))
self.pushButton_3.setText(_translate("MainWindow", "Set fully random MAC"))
self.pushButton_8.setText(_translate("MainWindow", "Reset MAC address to its original"))
self.pushButton_2.setText(_translate("MainWindow", "Don\'t change vendor bytes"))
self.pushButton_7.setText(_translate("MainWindow", "Reset MAC address to its original"))
self.pushButton_5.setText(_translate("MainWindow", "Set the MAC"))
self.label_4.setText(_translate("MainWindow", "TextLabel"))
self.pushButton_4.setText(_translate("MainWindow", "Set fully random MAC"))
self.label.setText(_translate("MainWindow", "TextLabel"))
self.label_2.setText(_translate("MainWindow", "TextLabel"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.menuEdit.setTitle(_translate("MainWindow", "Settings"))
self.menuHelp.setTitle(_translate("MainWindow", "Help"))
self.actionExit.setText(_translate("MainWindow", "Exit"))
self.actionPreferences.setText(_translate("MainWindow", "Preferences"))
self.actionAbout.setText(_translate("MainWindow", "About"))
def update_wired_label(self, MainWindow):
print('update_wired_label')
self.wired = config.get('ethernet', 'wired')
self.label.setText(str(self.wired))
def update_wired_mac_address_label(self, MainWindow):
print('update_wired_mac_address_label')
config.read('/home/user/.config/macspoof/macspoof.ini')
self.wired_mac_address = config.get('ethernet', 'wired_mac_address')
self.label_3.setText(str(self.wired_mac_address))
def update_wireless_label(self, MainWindow):
print('update_wireless_label')
self.wireless = config.get('wifi', 'wireless')
self.label_2.setText(str(self.wireless))
def update_wireless_mac_address_label(self, MainWindow):
print('update_wireless_mac_address_label')
config.read('/home/user/.config/macspoof/macspoof.ini')
self.wireless_mac_address = config.get('wifi', 'wireless_mac_address')
self.label_4.setText(str(self.wireless_mac_address))
def button_vendor_wired(self):
print('vendor_wired')
subprocess.run(['macchanger', '-e', wired])
macspoof_bash.vendor_wired()
self.update_wired_mac_address_label(MainWindow)
def button_fully_wired(self):
print('fully wired')
subprocess.run(['macchanger', '-r', wired])
macspoof_bash.write_to_ini()
self.update_wired_mac_address_label(MainWindow)
#def button_specific_wired(self):
# print('specific wired')
# subprocess.run(["macchanger", "-m", wired])
def button_original_wired(self):
print('original wired')
subprocess.run(['macchanger', '-p', wired])
macspoof_bash.write_to_ini()
self.update_wired_mac_address_label(MainWindow)
def button_vendor_wireless(self):
print('vendor_wireless')
subprocess.run(['macchanger', '-e', wireless])
macspoof_bash.vendor_wireless()
self.update_wireless_mac_address_label(MainWindow)
def button_fully_wireless(self):
print('fully wireless')
#wireless = config.get("wifi", "wireless")
#subprocess.run(['macchanger', '-r', wired])
macspoof_bash.fully_wireless()
self.update_wireless_mac_address_label(MainWindow)
def button_specific_wireless(self):
print('specific wired')
subprocess.run(["macchanger", "-m", wireless])
def button_original_wireless(self):
print('original wireless')
subprocess.run(['macchanger', '-p', wireless])
macspoof_bash.write_to_ini()
self.update_wireless_mac_address_label(MainWindow)
def close_window(self):
print("Quit")
sys.exit()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
secondWindow.py
from PyQt5 import QtCore, QtGui, QtWidgets
# Read and write settings in macspoof.ini file
from configparser import ConfigParser
# instantiate
config = ConfigParser()
# parse existing file
config.read('macspoof.ini')
# read values from a section
wired = config.get('ethernet', 'wired')
wired_mac_address = config.get('ethernet', 'wired_mac_address')
class Ui_macSpecific(object):
def setupUi(self, macSpecific, parent): # <--- add extra parameter parent
self.parent = parent # < --- create new attribute parent
#def setupUi(self, macSpecific):
macSpecific.setObjectName("macSpecific")
macSpecific.resize(301, 140)
self.gridLayout = QtWidgets.QGridLayout(macSpecific)
self.gridLayout.setObjectName("gridLayout")
self.label = QtWidgets.QLabel(macSpecific)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(10)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.lineEdit = QtWidgets.QLineEdit(macSpecific)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth())
self.lineEdit.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("DejaVu Sans")
font.setPointSize(14)
self.lineEdit.setFont(font)
self.lineEdit.setLayoutDirection(QtCore.Qt.LeftToRight)
self.lineEdit.setAutoFillBackground(False)
self.lineEdit.setAlignment(QtCore.Qt.AlignCenter)
self.lineEdit.setObjectName("lineEdit")
self.gridLayout.addWidget(self.lineEdit, 1, 0, 1, 1)
self.pushButton = QtWidgets.QPushButton(macSpecific, clicked = lambda: self.submit())
self.pushButton.setObjectName("pushButton")
self.gridLayout.addWidget(self.pushButton, 2, 0, 1, 1)
self.retranslateUi(macSpecific)
QtCore.QMetaObject.connectSlotsByName(macSpecific)
def retranslateUi(self, macSpecific):
_translate = QtCore.QCoreApplication.translate
macSpecific.setWindowTitle(_translate("macSpecific", "MAC address spoofing"))
self.label.setText(_translate("macSpecific", "Enter A MAC address"))
self.lineEdit.setText(_translate("macSpecific", "11:22:33:44:55:66"))
self.pushButton.setText(_translate("macSpecific", "Submit"))
def submit(self):
print("submit")
#self.parent.label_3.setText(str(self.wired_mac_address)) # use parent to set label text
self.parent.label_3.setText(str(self.parent.wired_mac_address)) # <-----Try this then.
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
macSpecific = QtWidgets.QDialog()
ui = Ui_macSpecific()
ui.setupUi(macSpecific)
macSpecific.show()
sys.exit(app.exec_())
One solution would be to assign the MainWindow as the parent of the SecondWindow. Then to get the label text all the SecondWindow has to do is self.parent.label.setText('something'). See the minor adjustments I made below.
mainWindow.py
class Ui_MainWindow(object):
def specificWindow(self):
self.window = QtWidgets.QDialog()
self.ui = Ui_macSpecific()
self.ui.setupUi(self.window, self) # <--- assign MainWindow as parent to second window
self.window.show()
secondWindow.py
import macspoof_bash
class Ui_macSpecific(object):
def setupUi(self, macSpecific, master):
self.master = master
self.window = macSpecific
macSpecific.setObjectName("macSpecific")
macSpecific.resize(301, 140)
...
...
self.pushButton = QtWidgets.QPushButton(macSpecific, clicked = lambda: self.submit())
def submit(self):
print("submit")
text = self.lineEdit.text()
self.master.label_3.setText(text)
self.window.close()
config['ethernet']['wired_mac_address'] = text
with open("macspoof.ini", "w") as inifile:
config.write(inifile)
I am working on a password manager gui app. Using Qtdesigner I created a main window where I asked for username and password from user. and a dialog window where display the user their username and passwords for different apps and websites. I also called that dialog window from my main window so that when user press login button then if their login credential is correct , the dialog window will appear.
Now what I want is that when dialog window appears,after clicking push button it should show all data of the user which is stored in a table with that username(like if username is alex then a table with name alex is there in db with username and passwords of different apps/websites).
Hope my question is understandable enough to be answered. I can further clarify if anyone interested to answer.
MY mainwindow file------>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'main.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3
from main2 import Ui_Dialog
class Ui_MainWindow(object):
def openwindow(self):
self.window = QtWidgets.QMainWindow()
self.ui = Ui_Dialog()
self.ui.setupUi(self.window)
self.window.show()
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(553, 400)
MainWindow.setMinimumSize(QtCore.QSize(553, 400))
MainWindow.setMaximumSize(QtCore.QSize(553, 400))
MainWindow.setAutoFillBackground(False)
MainWindow.setStyleSheet("background-color:\"PowderBlue\"")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(-1, -5, 561, 61))
font = QtGui.QFont()
font.setFamily("Dosis ExtraBold")
font.setPointSize(30)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setStyleSheet("color: rgb(87, 8, 97);")
self.label.setFrameShape(QtWidgets.QFrame.NoFrame)
self.label.setFrameShadow(QtWidgets.QFrame.Plain)
self.label.setLineWidth(7)
self.label.setObjectName("label")
self.frame = QtWidgets.QFrame(self.centralwidget)
self.frame.setGeometry(QtCore.QRect(28, 120, 511, 261))
self.frame.setStyleSheet("background-color: rgb(176, 224, 230);\n"
"")
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.username = QtWidgets.QLineEdit(self.frame)
self.username.setGeometry(QtCore.QRect(224, 0, 261, 41))
font = QtGui.QFont()
font.setFamily("Segoe Print")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
self.username.setFont(font)
self.username.setStyleSheet("border :2px solid purple ;\n"
"background-color:PowderBlue;\n"
"border-radius:5px;\n"
"\n"
"\n"
"\n"
"")
self.username.setText("")
self.username.setEchoMode(QtWidgets.QLineEdit.Normal)
self.username.setPlaceholderText("master user")
self.username.setClearButtonEnabled(False)
self.username.setObjectName("username")
self.label_2 = QtWidgets.QLabel(self.frame)
self.label_2.setGeometry(QtCore.QRect(442, 7, 41, 31))
self.label_2.setStyleSheet("image: url(:/user.png);\n"
"background-color:PowderBlue")
self.label_2.setText("")
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.frame)
self.label_3.setGeometry(QtCore.QRect(450, 69, 31, 31))
self.label_3.setAutoFillBackground(False)
self.label_3.setStyleSheet("image: url(:/key.png);\n"
"background-color:PowderBlue")
self.label_3.setText("")
self.label_3.setObjectName("label_3")
self.password = QtWidgets.QLineEdit(self.frame)
self.password.setGeometry(QtCore.QRect(225, 65, 261, 41))
font = QtGui.QFont()
font.setFamily("Segoe Print")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
self.password.setFont(font)
self.password.setPlaceholderText("master password")
self.password.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
self.password.setStyleSheet("border :2px solid purple ;\n"
"border-radius:5px;")
self.password.setText("")
self.password.setEchoMode(QtWidgets.QLineEdit.Password)
self.password.setPlaceholderText("")
self.password.setClearButtonEnabled(True)
self.password.setObjectName("password")
self.login_button = QtWidgets.QPushButton(self.frame,clicked=lambda:self.log_in())
self.login_button.setGeometry(QtCore.QRect(280, 130, 41, 31))
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.login_button.setFont(font)
self.login_button.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.login_button.setAcceptDrops(True)
self.login_button.setAutoFillBackground(False)
self.login_button.setStyleSheet("image: url(:/login.png);")
self.login_button.setText("")
self.login_button.setFlat(True)
self.login_button.setObjectName("login_button")
self.signup_button = QtWidgets.QPushButton(self.frame,clicked=lambda:self.sign_up())
self.signup_button.setGeometry(QtCore.QRect(388, 130, 41, 31))
self.signup_button.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.signup_button.setMouseTracking(False)
self.signup_button.setAcceptDrops(True)
self.signup_button.setAutoFillBackground(False)
self.signup_button.setStyleSheet("image: url(:/user (2).png);")
self.signup_button.setText("")
self.signup_button.setFlat(True)
self.signup_button.setObjectName("signup_button")
self.label_4 = QtWidgets.QLabel(self.frame)
self.label_4.setGeometry(QtCore.QRect(25, 7, 141, 141))
self.label_4.setStyleSheet("image: url(:/team.png);")
self.label_4.setText("")
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.frame)
self.label_5.setGeometry(QtCore.QRect(17, 135, 171, 41))
font = QtGui.QFont()
font.setFamily("Forte")
font.setPointSize(22)
font.setBold(False)
font.setWeight(50)
self.label_5.setFont(font)
self.label_5.setStyleSheet("color: rgb(5, 22, 127);")
self.label_5.setFrameShape(QtWidgets.QFrame.NoFrame)
self.label_5.setFrameShadow(QtWidgets.QFrame.Plain)
self.label_5.setLineWidth(7)
self.label_5.setObjectName("label_5")
self.error_lbl = QtWidgets.QLabel(self.frame)
self.error_lbl.setGeometry(QtCore.QRect(230,165,251,50))
#self.error_lbl.textFormat.RichText()
font = QtGui.QFont()
font.setFamily("Roboto Black")
font.setPointSize(11)
font.setBold(True)
font.setWeight(65)
self.error_lbl.setFont(font)
self.error_lbl.setStyleSheet("color: rgb(255,0,0);")
self.error_lbl.setFrameShape(QtWidgets.QFrame.NoFrame)
self.error_lbl.setFrameShadow(QtWidgets.QFrame.Plain)
self.error_lbl.setLineWidth(1)
self.error_lbl.setObjectName("error_lbl")
self.line_2 = QtWidgets.QFrame(self.frame)
self.line_2.setGeometry(QtCore.QRect(-17, 190, 20, 61))
self.line_2.setFrameShape(QtWidgets.QFrame.VLine)
self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_2.setObjectName("line_2")
self.line_5 = QtWidgets.QFrame(self.frame)
self.line_5.setGeometry(QtCore.QRect(520, -20, 20, 221))
self.line_5.setFrameShape(QtWidgets.QFrame.VLine)
self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_5.setObjectName("line_5")
self.label_6 = QtWidgets.QLabel(self.frame)
self.label_6.setGeometry(QtCore.QRect(349, 231, 41, 31))
self.label_6.setStyleSheet("image: url(:/copyright.png);")
self.label_6.setText("")
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.frame)
self.label_7.setGeometry(QtCore.QRect(380, 234, 111, 20))
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label_7.setFont(font)
self.label_7.setObjectName("label_7")
self.password.raise_()
self.username.raise_()
self.label_2.raise_()
self.label_3.raise_()
self.login_button.raise_()
self.signup_button.raise_()
self.label_4.raise_()
self.label_5.raise_()
self.error_lbl.raise_()
self.line_2.raise_()
self.line_5.raise_()
self.label_6.raise_()
self.label_7.raise_()
self.info_button = QtWidgets.QPushButton(self.centralwidget)
self.info_button.setGeometry(QtCore.QRect(510, 0, 41, 23))
self.info_button.setStyleSheet("image: url(:/information-button.png);")
self.info_button.setText("")
self.info_button.setFlat(True)
self.info_button.setObjectName("info_button")
self.line_3 = QtWidgets.QFrame(self.centralwidget)
self.line_3.setGeometry(QtCore.QRect(9, 101, 20, 271))
self.line_3.setFrameShape(QtWidgets.QFrame.VLine)
self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_3.setObjectName("line_3")
self.line_6 = QtWidgets.QFrame(self.centralwidget)
self.line_6.setGeometry(QtCore.QRect(520, 101, 21, 271))
self.line_6.setFrameShape(QtWidgets.QFrame.VLine)
self.line_6.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_6.setObjectName("line_6")
self.label_8 = QtWidgets.QLabel(self.centralwidget)
self.label_8.setGeometry(QtCore.QRect(334, 0, 81, 61))
self.label_8.setStyleSheet("image: url(:/password.png);")
self.label_8.setText("")
self.label_8.setObjectName("label_8")
self.line_8 = QtWidgets.QFrame(self.centralwidget)
self.line_8.setGeometry(QtCore.QRect(19, 90, 511, 20))
self.line_8.setFrameShape(QtWidgets.QFrame.HLine)
self.line_8.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_8.setObjectName("line_8")
self.line_4 = QtWidgets.QFrame(self.centralwidget)
self.line_4.setGeometry(QtCore.QRect(19, 364, 361, 16))
self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_4.setObjectName("line_4")
self.line_7 = QtWidgets.QFrame(self.centralwidget)
self.line_7.setGeometry(QtCore.QRect(513, 364, 16, 16))
self.line_7.setFrameShape(QtWidgets.QFrame.HLine)
self.line_7.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_7.setObjectName("line_7")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 553, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def log_in(self):
conn = sqlite3.connect("master.db")
cur = conn.cursor()
user = self.username.text()
password = self.password.text()
print(user)
print(password)
if user=="" or password=="" :
self.error_lbl.setText( "materuser & masterpassword\nrequired !")
else:
cur.execute("SELECT rowid , *FROM master_database WHERE master_users = ?", (user,))
c=cur.fetchone()
conn.commit()
conn.close()
if c==None:
self.error_lbl.setText( f"No data for {user}\nKindly register for new user !" )
else:
if c[2] == password:
#self.error_lbl.setText("Successfully verified.\nClick to Login")
self.window = QtWidgets.QMainWindow()
self.ui = Ui_Dialog()
self.ui.setupUi(self.window)
self.window.show()
else:
self.error_lbl.setText("Incorrect Password !" )
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
My Dialog window file------->'
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'main2.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3
class Ui_Dialog(object):
def loaddata(self):
connection = sqlite3.connect('master.db')
query = "SELECT * FROM a"
c = connection.execute(query)
self.tableWidget.setRowCount(0)
for row_number , row_data in enumerate(c):
self.tableWidget.insertRow(row_number)
for column_number ,data in enumerate(row_data):
self.tableWidget.setItem(row_number,column_number,QtWidgets.QTableWidgetItem(str(data)))
connection.commit()
connection.close()
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(553, 424)
font = QtGui.QFont()
font.setFamily("Consolas")
Dialog.setFont(font)
Dialog.setStyleSheet("background-color: PowderBlue;bn ")
self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(36, 112, 151, 31))
font = QtGui.QFont()
font.setFamily("Raleway Black")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(Dialog)
self.label_5.setGeometry(QtCore.QRect(225, 112, 111, 31))
font = QtGui.QFont()
font.setFamily("Raleway Black")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label_5.setFont(font)
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(Dialog)
self.label_6.setGeometry(QtCore.QRect(396, 112, 121, 31))
font = QtGui.QFont()
font.setFamily("Raleway Black")
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label_6.setFont(font)
self.label_6.setObjectName("label_6")
self.tableWidget = QtWidgets.QTableWidget(Dialog)
self.tableWidget.setGeometry(QtCore.QRect(10, 150, 531, 271))
self.tableWidget.setMinimumSize(QtCore.QSize(531, 271))
self.tableWidget.setMaximumSize(QtCore.QSize(531, 271))
font = QtGui.QFont()
font.setFamily("Source Sans Pro SemiBold")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.tableWidget.setFont(font)
self.tableWidget.setStyleSheet("color: rgb(73, 6, 127);")
self.tableWidget.setFrameShape(QtWidgets.QFrame.Box)
self.tableWidget.setGridStyle(QtCore.Qt.NoPen)
self.tableWidget.setRowCount(10)
self.tableWidget.setColumnCount(3)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.horizontalHeader().setDefaultSectionSize(177)
self.pushButton = QtWidgets.QPushButton(Dialog,clicked=lambda:self.loaddata())
self.pushButton.setGeometry(QtCore.QRect(200, 30, 75, 23))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label_4.setText(_translate("Dialog", "APP/WEBSITE"))
self.label_5.setText(_translate("Dialog", "USERNAME"))
self.label_6.setText(_translate("Dialog", "PASSWORD"))
self.pushButton.setText(_translate("Dialog", "PushButton"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
I use the QStackedWidget to switch between pages.
app = QApplication(sys.argv)
stackedwidget = QtWidgets.QStackedWidget()
page1 = PageOneClass()
page2 = PageTwoClass()
stackedwidget.addWidget(page1)
stackedwidget.addWidget(page2)
stackedwidget.show()
app.exec_()
This will let you switch between pages without running another file. Now to get values from one page to another, use inheritance.
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.user = self.username.text()
self password = self.password.text() #Now the user, password can be accessed using the class name. dont forget to add self.
class DialogWindow(MainWindow):
def __init__(self, MainWindow):
super(DialogWindow, self).__init__()
usernamefrompage1 = MainWindow.user
passwordfrompage1 = MainWindow.password
app = QApplication(sys.argv)
stackedwidget = QtWidgets.QStackedWidget()
mainwindow_instance = MainWindow()
dialogwindow_instance = DialogWindow(mainwindow_instance)
#we are passing the mainwindow instance to the dialog window instance, this will let us use all the methods and attributes of the mainwindow.
stackedwidget.addWidget(mainwindow_instance)
stackedwidget.addWidget(dialogwindow_instance)
stackedwidget.setCurrentWidget(mainwindow_instance)
stackedwidget.show()
app.exec_()
I want to automatically popup to another window,for test ,i add a buttom in my GUI,but there is nothing happened.What's more ,i do not want my thread killed,because it has happened before.How can I recorrecct my code?
main.py
from PyQt5 import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import sys
import time
from alert import Ui_Dialog
class Ui_Control_system(object):
def setupUi(self, Control_system):
Control_system.setObjectName("Control_system")
Control_system.resize(1004, 722)
Control_system.setFixedSize(1004, 722)
Control_system.setWindowIcon(QIcon('images/icon.png'))
Control_system.setStyleSheet("QMainWindow{border-image:url(images/background.jpg)}")
self.centralwidget = QtWidgets.QWidget(Control_system)
self.centralwidget.setObjectName("centralwidget")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(130, 170, 752, 245))
self.tableWidget.setRowCount(8)
self.tableWidget.setColumnCount(6)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.horizontalHeader().setVisible(False)
self.tableWidget.horizontalHeader().setCascadingSectionResizes(False)
self.tableWidget.horizontalHeader().setDefaultSectionSize(125)
self.tableWidget.horizontalHeader().setHighlightSections(True)
self.tableWidget.horizontalHeader().setSortIndicatorShown(False)
self.tableWidget.verticalHeader().setVisible(False)
Control_system.setCentralWidget(self.centralwidget)
self.tableWidget.setAutoFillBackground(True)
self.tableWidget.setItem(0,0,QTableWidgetItem("机器编号"))
self.tableWidget.setItem(0,1,QTableWidgetItem("烟雾值"))
self.tableWidget.setItem(0,2,QTableWidgetItem("火焰值"))
self.tableWidget.setItem(0,3, QTableWidgetItem("温度值"))
self.tableWidget.setItem(0,4, QTableWidgetItem("电流值"))
self.tableWidget.setItem(0,5, QTableWidgetItem("电压值"))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
self.tableWidget.item(0,0).setFont(font)
self.tableWidget.item(0,1).setFont(font)
self.tableWidget.item(0,2).setFont(font)
self.tableWidget.item(0,3).setFont(font)
self.tableWidget.item(0,4).setFont(font)
self.tableWidget.item(0,5).setFont(font)
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(360, 70, 300, 50))
self.label.setObjectName("label")
self.label.setAutoFillBackground(True)
self.label.setAlignment(Qt.AlignCenter)
self.label.setStyleSheet("border-image:url(images/title.png)")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(560, 480, 121, 41))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(730, 480, 121, 41))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(70, 60, 121, 41))
self.pushButton_3.setObjectName("pushButton_3")
Control_system.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(Control_system)
self.statusbar.setObjectName("statusbar")
Control_system.setStatusBar(self.statusbar)
self.retranslateUi(Control_system)
QtCore.QMetaObject.connectSlotsByName(Control_system)
def retranslateUi(self, Control_system):
_translate = QtCore.QCoreApplication.translate
Control_system.setWindowTitle(_translate("Control_system", "实时监控系统"))
self.pushButton.setText(_translate("Control_system", "开始运行"))
self.pushButton_2.setText(_translate("Control_system", "停止"))
self.pushButton_3.setText(_translate("Control_system", "跳转"))
class Control_system(QtWidgets.QMainWindow, Ui_Control_system):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.pushButton_3.clicked.connect(self.jump_to_alert)
#QtCore.pyqtSlot()
def jump_to_alert(self):
self.popup_window_thread = PopupWindow(self)
self.popup_window_thread.start()
class Alert(QtWidgets.QDialog,Ui_Dialog):
def __init__(self):
QtWidgets.QDialog.__init__(self)
self.alert=Ui_Dialog()
self.alert.setupUi(self)
def closeEvent(self, event):
reply = QtWidgets.QMessageBox.question(self,
'警告',
"是否要退出警告?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
event.accept()
else:
event.ignore()
class PopupWindow(QtCore.QThread):
def __init__(self, parent=None):
super(PopupWindow, self).__init__()
self.index = 0
def run(self):
self.index+=1
while self.index <= 3:
alert = Alert()
alert.show()
alert.exec()
time.sleep(1)
def stop(self):
self.quit()
self.wait()
if __name__ == '__main__':
if not QtWidgets.QApplication.instance():
app = QtWidgets.QApplication(sys.argv)
else:
app = QtWidgets.QApplication.instance()
w = Control_system()
w.show()
app.exec()
this is another UI,which will popup to
alert.py
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(557, 444)
Dialog.setStyleSheet("QMainWindow{border-image:url(images/background.jpg)}")
Dialog.setWindowIcon(QIcon('images/icon.png'))
self.textBrowser = QtWidgets.QTextBrowser(Dialog)
self.textBrowser.setGeometry(QtCore.QRect(200, 80, 256, 41))
self.textBrowser.setObjectName("textBrowser")
self.textBrowser_2 = QtWidgets.QTextBrowser(Dialog)
self.textBrowser_2.setGeometry(QtCore.QRect(200, 170, 256, 41))
self.textBrowser_2.setObjectName("textBrowser_2")
self.textBrowser_3 = QtWidgets.QTextBrowser(Dialog)
self.textBrowser_3.setGeometry(QtCore.QRect(200, 260, 256, 41))
self.textBrowser_3.setObjectName("textBrowser_3")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(60, 80, 111, 31))
font = QtGui.QFont()
font.setFamily("微软雅黑")
font.setPointSize(20)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setStyleSheet("color: rgb(255, 0, 0);")
self.label.setTextFormat(QtCore.Qt.AutoText)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(60, 170, 111, 31))
font = QtGui.QFont()
font.setFamily("微软雅黑")
font.setPointSize(20)
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setStyleSheet("color: rgb(255, 0, 0);")
self.label_2.setTextFormat(QtCore.Qt.AutoText)
self.label_2.setObjectName("label_2")
self.alert = QtWidgets.QLabel(Dialog)
self.alert.setGeometry(QtCore.QRect(60, 260, 111, 31))
font = QtGui.QFont()
font.setFamily("微软雅黑")
font.setPointSize(20)
font.setBold(True)
font.setWeight(75)
self.alert.setFont(font)
self.alert.setStyleSheet("color: rgb(255, 0, 0);")
self.alert.setTextFormat(QtCore.Qt.AutoText)
self.alert.setObjectName("alert")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "警告"))
self.label.setText(_translate("Dialog", "报警车间"))
self.label_2.setText(_translate("Dialog", "报警机器"))
self.alert.setText(_translate("Dialog", "报警项目"))
Try it:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import time
from alert import Ui_Dialog
class Ui_Control_system(object):
def setupUi(self, Control_system):
Control_system.setObjectName("Control_system")
Control_system.resize(1004, 722)
Control_system.setFixedSize(1004, 722)
Control_system.setWindowIcon(QIcon('images/icon.png'))
Control_system.setStyleSheet("QMainWindow{border-image:url(images/background.jpg)}")
self.centralwidget = QtWidgets.QWidget(Control_system)
self.centralwidget.setObjectName("centralwidget")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(130, 170, 752, 245))
self.tableWidget.setRowCount(8)
self.tableWidget.setColumnCount(6)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.horizontalHeader().setVisible(False)
self.tableWidget.horizontalHeader().setCascadingSectionResizes(False)
self.tableWidget.horizontalHeader().setDefaultSectionSize(125)
self.tableWidget.horizontalHeader().setHighlightSections(True)
self.tableWidget.horizontalHeader().setSortIndicatorShown(False)
self.tableWidget.verticalHeader().setVisible(False)
Control_system.setCentralWidget(self.centralwidget)
self.tableWidget.setAutoFillBackground(True)
self.tableWidget.setItem(0,0,QTableWidgetItem("机器编号"))
self.tableWidget.setItem(0,1,QTableWidgetItem("烟雾值"))
self.tableWidget.setItem(0,2,QTableWidgetItem("火焰值"))
self.tableWidget.setItem(0,3, QTableWidgetItem("温度值"))
self.tableWidget.setItem(0,4, QTableWidgetItem("电流值"))
self.tableWidget.setItem(0,5, QTableWidgetItem("电压值"))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
self.tableWidget.item(0,0).setFont(font)
self.tableWidget.item(0,1).setFont(font)
self.tableWidget.item(0,2).setFont(font)
self.tableWidget.item(0,3).setFont(font)
self.tableWidget.item(0,4).setFont(font)
self.tableWidget.item(0,5).setFont(font)
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(360, 70, 300, 50))
self.label.setObjectName("label")
self.label.setAutoFillBackground(True)
self.label.setAlignment(Qt.AlignCenter)
self.label.setStyleSheet("border-image:url(images/title.png)")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(560, 480, 121, 41))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(730, 480, 121, 41))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(70, 60, 121, 41))
self.pushButton_3.setObjectName("pushButton_3")
Control_system.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(Control_system)
self.statusbar.setObjectName("statusbar")
Control_system.setStatusBar(self.statusbar)
self.retranslateUi(Control_system)
QtCore.QMetaObject.connectSlotsByName(Control_system)
def retranslateUi(self, Control_system):
_translate = QtCore.QCoreApplication.translate
Control_system.setWindowTitle(_translate("Control_system", "实时监控系统"))
self.pushButton.setText(_translate("Control_system", "开始运行"))
self.pushButton_2.setText(_translate("Control_system", "停止"))
self.pushButton_3.setText(_translate("Control_system", "跳转"))
class Control_system(QtWidgets.QMainWindow, Ui_Control_system):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.pushButton_3.clicked.connect(self.jump_to_alert)
#QtCore.pyqtSlot()
def jump_to_alert(self):
self.popup_window_thread = PopupWindow(self)
self.popup_window_thread.popup.connect(self.goAlert) # +++
self.popup_window_thread.start()
def goAlert(self): # +++
self.alert = Alert()
self.alert.show()
class Alert(QtWidgets.QDialog,Ui_Dialog):
def __init__(self):
QtWidgets.QDialog.__init__(self)
self.alert=Ui_Dialog()
self.alert.setupUi(self)
def closeEvent(self, event):
reply = QtWidgets.QMessageBox.question(self,
'警告',
"是否要退出警告?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
event.accept()
else:
event.ignore()
class PopupWindow(QtCore.QThread):
popup = pyqtSignal() # +++
def __init__(self, parent=None):
super(PopupWindow, self).__init__()
self.index = 0
def run(self):
# self.index+=1
self.popup.emit() # +++
while self.index <= 3:
# alert = Alert()
# alert.show()
# alert.exec()
self.index += 1 # +++
time.sleep(1)
def stop(self):
self.quit()
self.wait()
if __name__ == '__main__':
if not QtWidgets.QApplication.instance():
app = QtWidgets.QApplication(sys.argv)
else:
app = QtWidgets.QApplication.instance()
w = Control_system()
w.show()
app.exec()
I tried writing some codes using pyqt5 and have two main windows and push buttons, for both cases I have done same but one works on clicked.connect and one doesn't. Pasting code for the button which doesn't work. I call this window after closing first one
I tried creating module outside of class and that worked but then struggled with referencing to lineEdit objects
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
app = QtWidgets.QApplication(sys.argv)
PREMIX = QtWidgets.QMainWindow()
logo = QtGui.QIcon()
def init_login():
ui = Ui_PREMIXlogin()
ui.setupUi(PREMIX)
PREMIX.show()
sys.exit(app.exec_())
def close_login():
PREMIX.hide()
def init_main():
ui = Ui_PREMIX()
ui.setupUi(PREMIX)
PREMIX.show()
class Ui_PREMIXlogin(object):
def setupUi(self, PREMIXlogin):
PREMIXlogin.setObjectName("PREMIXlogin")
PREMIXlogin.setEnabled(True)
PREMIXlogin.resize(280, 319)
sizePolicy = QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed
)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(
PREMIXlogin.sizePolicy().hasHeightForWidth()
)
PREMIXlogin.setSizePolicy(sizePolicy)
PREMIXlogin.setMinimumSize(QtCore.QSize(280, 319))
PREMIXlogin.setMaximumSize(QtCore.QSize(280, 319))
PREMIXlogin.setMouseTracking(False)
PREMIXlogin.setWindowIcon(logo)
PREMIXlogin.setAutoFillBackground(False)
PREMIXlogin.setStyleSheet("background-color: rgb(255, 255, 255);")
self.centralwidget = QtWidgets.QWidget(PREMIXlogin)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(36, 190, 61, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(36, 220, 61, 20))
font = QtGui.QFont()
font.setPointSize(10)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(110, 190, 113, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(110, 220, 113, 20))
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.lineEdit_2.setFont(font)
self.lineEdit_2.setInputMethodHints(
QtCore.Qt.ImhHiddenText
| QtCore.Qt.ImhNoAutoUppercase
| QtCore.Qt.ImhNoPredictiveText
| QtCore.Qt.ImhSensitiveData
)
self.lineEdit_2.setFrame(True)
self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
self.lineEdit_2.setObjectName("lineEdit_2")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(100, 260, 81, 31))
font = QtGui.QFont()
font.setPointSize(11)
font.setBold(False)
font.setWeight(50)
self.pushButton.setFont(font)
self.pushButton.setAutoFillBackground(False)
self.pushButton.setStyleSheet("background-color: rgb(222, 31, 38);")
self.pushButton.setObjectName("pushButton")
self.frame = QtWidgets.QFrame(self.centralwidget)
self.frame.setGeometry(QtCore.QRect(30, 20, 231, 151))
self.frame.setStyleSheet(
"image: url(:/images/59301307_2353273704903079_3349139235981492224_n.png);"
)
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
PREMIXlogin.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(PREMIXlogin)
self.statusbar.setObjectName("statusbar")
PREMIXlogin.setStatusBar(self.statusbar)
self.retranslateUi(PREMIXlogin)
QtCore.QMetaObject.connectSlotsByName(PREMIXlogin)
def retranslateUi(self, PREMIXlogin):
_translate = QtCore.QCoreApplication.translate
PREMIXlogin.setWindowTitle(_translate("PREMIXlogin", "PREMIX Login"))
self.label.setText(_translate("PREMIXlogin", "Username"))
self.label_2.setText(_translate("PREMIXlogin", "Password"))
self.pushButton.setText(_translate("PREMIXlogin", "Log in"))
self.pushButton.clicked.connect(self.on_click)
def on_click(self):
if True:
close_login()
init_main()
class Ui_PREMIX(object):
def setupUi(self, PREMIX):
PREMIX.setObjectName("PREMIX")
PREMIX.resize(473, 179)
sizePolicy = QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed
)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(PREMIX.sizePolicy().hasHeightForWidth())
PREMIX.setSizePolicy(sizePolicy)
PREMIX.setMinimumSize(QtCore.QSize(473, 179))
PREMIX.setMaximumSize(QtCore.QSize(473, 179))
PREMIX.setStyleSheet("background-color: rgb(255, 255, 255);")
PREMIX.setWindowIcon(logo)
self.centralwidget = QtWidgets.QWidget(PREMIX)
self.centralwidget.setObjectName("centralwidget")
self.Product = QtWidgets.QLabel(self.centralwidget)
self.Product.setGeometry(QtCore.QRect(30, 20, 61, 20))
font = QtGui.QFont()
font.setPointSize(13)
self.Product.setFont(font)
self.Product.setObjectName("Product")
self.Productname = QtWidgets.QLineEdit(self.centralwidget)
self.Productname.setGeometry(QtCore.QRect(100, 20, 251, 20))
self.Productname.setObjectName("Productname")
self.Checkbutton = QtWidgets.QPushButton(self.centralwidget)
self.Checkbutton.setGeometry(QtCore.QRect(370, 20, 81, 21))
font = QtGui.QFont()
font.setPointSize(11)
font.setBold(False)
font.setWeight(50)
self.Checkbutton.setFont(font)
self.Checkbutton.setAutoFillBackground(False)
self.Checkbutton.setStyleSheet("background-color: rgb(222, 31, 38);")
self.Checkbutton.setObjectName("Checkbutton")
self.logo = QtWidgets.QFrame(self.centralwidget)
self.logo.setGeometry(QtCore.QRect(359, 60, 101, 80))
self.logo.setStyleSheet(
"image: url(:/images/59301307_2353273704903079_3349139235981492224_n.png);"
)
self.logo.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.logo.setFrameShadow(QtWidgets.QFrame.Raised)
self.logo.setObjectName("logo")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(180, 80, 91, 31))
self.lineEdit.setMinimumSize(QtCore.QSize(89, 31))
self.lineEdit.setMaximumSize(QtCore.QSize(91, 31))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit.setReadOnly(True)
PREMIX.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(PREMIX)
self.statusbar.setObjectName("statusbar")
PREMIX.setStatusBar(self.statusbar)
self.retranslateUi(PREMIX)
QtCore.QMetaObject.connectSlotsByName(PREMIX)
def retranslateUi(self, PREMIX):
_translate = QtCore.QCoreApplication.translate
PREMIX.setWindowTitle(_translate("PREMIX", "PREMIX"))
self.Product.setText(_translate("PREMIX", "Product"))
self.Checkbutton.setText(_translate("PREMIX", "Check"))
self.Checkbutton.clicked.connect(self.on_click)
def on_click(self):
print("aaaaaa")
product = self.Productname.text()
print(product)
def main():
init_login()
if __name__ == "__main__":
main()
I want Checkbutton on click event to work, please help
For Ui_Premix, used self.Checkbutton.clicked.connect(Ui_PREMIX.on_click) instead of
self.on_click even though on_click event was inside class, it works now