我试图通过单击单选按钮从数据库表中获取记录。但是,这些项目没有显示在我的listview小部件中,并且在单击单选按钮后界面崩溃。请帮助我。
我的代码:
def working(self,action):
txt=(action.text())
cricket=Ui_MainWindow.connect('cricket.db')
sql="SELECT player from statistics WHERE ctg='BAT';";
sql1="SELECT player from statistics WHERE ctg='BOWL';";
sql2="SELECT player from statistics WHERE ctg='AR';";
sql3="SELECT player from statistics WHERE ctg='WK';";
curse=cricket.cursor()
#i=random.randint(1,30)
if(radioButton.isChecked()):
try:
curse.execute(sql)
rec=curse.fetchall()
listWidget.additems(rec)
except:
print("error")
elif(radioButton_2.isChecked()):
try:
curse.execute(sql1)
rec=curse.fetchall()
listWidget.additems(rec)
except:
print("error")
elif(radioButton_3.isChecked()):
try:
curse.execute(sql2)
rec=curse.fetchall()
listWidget.additems(rec)
except:
print("error")
elif(radioButton_4.isChecked()):
try:
curse.execute(sql3)
rec=curse.fetchall()
listWidget.additems(rec)
except:
print("error")
我尝试在命令提示符下运行sql命令,并且记录在那里显示而没有任何错误。
编辑:我也已在我的setupUi
方法中添加了这些
self.radioButton.toggled.connect(self.working)
self.radioButton_2.toggled.connect(self.working)
self.radioButton_3.toggled.connect(self.working)
self.radioButton_4.toggled.connect(self.working)