如果我的标题不清楚,我很抱歉;我正在尝试从SQLLite数据库(正在工作)中检索一些数据,并在PyQt5中的窗口中显示给用户。到目前为止,我已经成功地检索到结果并用Python打印,但是当试图在窗口中添加/查看结果时,Python就崩溃了。 我插入了下面不起作用的代码。(复制时缩进有点滑稽,但在我的文件中它是完美的)。在
class Profile(QWidget):
def __init__(self, Type):
super().__init__()
self.window = QWidget()
self.window.setGeometry(100,100, 350, 400)
self.window.setWindowTitle("Welcome")
self.window.show()
self.Choices()
def Choices(self):
self.layout = QGridLayout()
c.execute('''SELECT username, teamname FROM Users WHERE username = ?''',
(user,))
result = c.fetchone()
print(result)
print(user)
self.TeamInfo = QLabel(result)
self.layout.addWidget(self.TeamInfo)
self.window.setLayout(self.layout)
self.window.show()
user
是前一个窗口(登录页面)中的全局变量,以避免用户必须重新输入用户名。本节不包括在内,因为这不是问题所在。这个类中所有其他的按钮都起作用了-只是这个特殊的部分。任何关于如何解决这个问题的帮助都是非常感谢的,我认为问题是self.TeamInfo = QLabel(result)
,但我不知道如何解决这个问题。在
编辑:我已经包含了一个错误消息的截图。在
如果我理解正确的话,你想在QLabel中添加一个文本,对吗? 根据文档,向其添加文本的操作是:
QLabel().setText(result)
。在编辑:你能试试这个,告诉我编译器在抱怨什么吗?在
试试看:
相关问题 更多 >
编程相关推荐