python - 当我从另一个 QMainWindow 传递参数后要求另一个 QMainWindow 出现时,它没有出现?
问题描述
这是我在从我的数据库获取到 ProfW 后尝试传递 Id 的登录类,它正确传递,但是当我调用 ProfW.show() 时窗口没有出现。
class Login(QMainWindow):
def __init__(self):
super(Login, self).__init__()
self.setFixedWidth(1030)
self.setFixedHeight(590)
loadUi("loginW.ui", self)
self.back.setStyleSheet("background-image : url(MainBack.png)")
self.back.resize(1060, 625)
self.LoginButton.clicked.connect(self.loginfunction)
self.ReButton.clicked.connect(self.Register)
def loginfunction(self):
if db_connection.is_connected() == False:
db_connection.connect()
db_cursor.execute("CREATE DATABASE IF NOT EXISTS User")
db_cursor.execute("use User")
db_cursor.execute(
"Create table if not exists USER(Id VARCHAR(30) NOT NULL PRIMARY KEY,password VARCHAR(30),fname VARCHAR(30),lname VARCHAR(30),Email VARCHAR(30))")
db_connection.commit()
# Get Login Info
email = self.email.text()
Password1 = self.Password.text()
# Check if user exist
query = "SELECT Id FROM User WHERE Email ='%s' AND password ='%s'" % (email, Password1)
db_cursor.execute(query)
try:
db_cursor.execute(query)
info = db_cursor.fetchall()
result = db_cursor.rowcount
if result == 1:
res = any(chr.isdigit() for chr in email)
if res:
StuW.show()
else:
Profw = Professor.ProfessorI(info[0][0])
Profw.show()
else:
msgf = QMessageBox()
msgf.setIcon(QMessageBox.Warning)
msgf.setText("Incorrect email or password ")
msgf.setInformativeText("Please try again.")
msgf.setWindowTitle("Warning!")
retval = msgf.exec_()
except mc.Error as e:
msgf = QMessageBox()
msgf.setIcon(QMessageBox.Warning)
msgf.setText("Something wrong happened!")
msgf.setInformativeText("Please try login again.")
msgf.setWindowTitle("Warning!")
retval = msgf.exec_()
这是我的教授窗口的代码,我想要一个隐藏的单选按钮显示教授课程编号,每个用户都不同。教授 QMainWindow 栏出现和消失的速度非常快,并且什么也没有出现。
class ProfessorI(QMainWindow):
def __init__(self,id):
self.id=id
super(ProfessorI, self).__init__()
self.setFixedWidth(1030)
self.setFixedHeight(590)
loadUi("ProfW.ui", self)
self.back.setStyleSheet("background-image : url(PSBackground.png)")
# self.back.resize(1060, 625)
# self.WL = 'Hello Professor'+' Welcome to MiniProctor'
self.SetWindow = SettingI()
self.radioButton1.setHidden(True)
self.radioButton2.setHidden(True)
self.radioButton3.setHidden(True)
self.radioButton4.setHidden(True)
self.radioButton5.setHidden(True)
self.SettingButton.clicked.connect(self.ShowSW)
self.LogoutButton.clicked.connect(self.LogoutW)
self.GetCourse()
def ShowSW(self):
# TODO: Check box for enable Face and voice recognition
# SetWindow.show()
self.SetWindow.show()
def LogoutW(self):
# TODO: Save info and logout
# Profw.hide()
print('LOGOUT')
# Fetch Professor Course
def GetCourse(self):
if db_connection.is_connected() == False:
db_connection.connect()
db_cursor.execute("use User")
db_cursor.execute(
"Create table if not exists Course(CourseId INT(30) NOT NULL PRIMARY KEY, Name VARCHAR(30), FOREIGN KEY(DrId) REFERENCES USER(Id),FOREIGN KEY(StID) REFERENCES USER(Id))")
db_connection.commit()
query = "SELECT Name FROM Course WHERE DrId ='%s'" % self.id
db_cursor.execute(query)
# # display all records
# table = db_cursor.fetchall()
result = db_cursor.rowcount
# id= MiniLogin.Login.getid(self)
# Id = table[1]
if result == 1:
result = db_cursor.rowcount
for x in range(1, result, 1):
n = "radioButton" + x
self.RadioButton = self.findChild(self.QRadioButton, n)
self.RadioButton.setHidden(False)
try:
db_cursor.execute(query)
# display all records
table = db_cursor.fetchall()
result = db_cursor.rowcount
#Id = table[0]
if result == 1:
result = db_cursor.rowcount
for x in range(1, result, 1):
n = "radioButton" + x
self.RadioButton = self.findChild(self.QRadioButton, n)
self.RadioButton.setHidden(False)
except mc.Error as e:
msgf = QMessageBox()
msgf.setIcon(QMessageBox.Warning)
msgf.setText("Something wrong happened!")
msgf.setInformativeText("Please try login again.")
msgf.setWindowTitle("Warning!")
retval = msgf.exec_()
解决方案
推荐阅读
- mysql - 在 MySQL 中添加第三个表的 WHERE 子句,其 ID 存在于前两个内连接表中
- java - ClassCastException While Create an org.apache.poi.poifs.crypt.EncryptionInfo Instance (Apache POI)
- c# - 包括 ASP.net Identity LoginPartial In Menu - 用户未登录
- django - Django中的get_queryset vs manager
- excel - 如何创建将单个选项卡excel转换为字段包含分号的csv文件的vb脚本
- android - 如何解决我的应用程序的问题(只显示视图寻呼机)?
- r - `dplyr::n_distinct` 函数的问题
- command-line - python -m vs 直接命令
- javascript - 对象中的错误计数以及在对象和数组之间计算相同值的正确方法
- php - PHP:JSON 中的正则表达式导致 json_decode 出现问题?