Я пытаюсь отобразить список из базы данных в QListWidget в соответствии с включенным QRadioButton. Я использовал QButtonGroup для 4 QRadioButton. Я хочу, чтобы список игроков, связанных с категориями, отображался в QListWidget, который извлекается из базы данных при проверке QradioButton. Но когда я нажимаю QRadioButton, он показывает, что python перестал работать. Вот мой код.
from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3
db=sqlite3.connect("fantcktdb.db")
cur=db.cursor()
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.frame = QtWidgets.QFrame(self.centralwidget)
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.gridLayout_2 = QtWidgets.QGridLayout(self.frame)
self.gridLayout_2.setObjectName("gridLayout_2")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.wkRadio = QtWidgets.QRadioButton(self.frame)
self.wkRadio.setObjectName("wkRadio")
self.buttonGroup = QtWidgets.QButtonGroup(MainWindow)
self.buttonGroup.setObjectName("buttonGroup")
self.buttonGroup.addButton(self.wkRadio)
self.verticalLayout.addWidget(self.wkRadio)
self.arRadio = QtWidgets.QRadioButton(self.frame)
self.arRadio.setObjectName("arRadio")
self.buttonGroup.addButton(self.arRadio)
self.verticalLayout.addWidget(self.arRadio)
self.bowRadio = QtWidgets.QRadioButton(self.frame)
self.bowRadio.setObjectName("bowRadio")
self.buttonGroup.addButton(self.bowRadio)
self.verticalLayout.addWidget(self.bowRadio)
self.batRadio = QtWidgets.QRadioButton(self.frame)
self.batRadio.setObjectName("batRadio")
self.buttonGroup.addButton(self.batRadio)
self.verticalLayout.addWidget(self.batRadio)
self.buttonGroup.buttonToggled.connect(self.showList)
self.listWidget = QtWidgets.QListWidget(self.frame)
self.listWidget.setObjectName("listWidget")
self.verticalLayout.addWidget(self.listWidget)
self.gridLayout_2.addLayout(self.verticalLayout, 0, 0, 1, 1)
self.gridLayout.addWidget(self.frame, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 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)
def showList(self,MainWindow):
if (self.batRadio.isChecked()==True):
cur.execute('''SELECT Player FROM stats WHERE Ctg='BAT';''')
records=cur.fetchall()
self.listWidget.clear()
for row in records:
self.listWidget.addItems(row)
self.listWidget.update()
elif (self.bowRadio.isChecked()==True):
cur.execute('''SELECT Player FROM stats WHERE Ctg='BOW';''')
records=cur.fetchall()
self.listWidget.clear()
for row in records:
self.listWidget.addItems(row)
self.listWidget.update()
elif (self.arRadio.isChecked()==True):
cur.execute('''SELECT Player FROM stats WHERE Ctg='AR';''')
records=cur.fetchall()
self.listWidget.clear()
for row in records:
self.listWidget.addItems(row)
self.listWidget.update()
elif (self.wkRadio.isChecked()==True):
cur.execute('''SELECT Player FROM stats WHERE Ctg='WK';''')
records=cur.fetchall()
self.listWidget.clear()
for row in records:
self.listWidget.addItems(row)
self.listWidget.update()
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.wkRadio.setText(_translate("MainWindow", "WK"))
self.arRadio.setText(_translate("MainWindow", "AR"))
self.bowRadio.setText(_translate("MainWindow", "BOW"))
self.batRadio.setText(_translate("MainWindow", "BAT"))
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_())