PyQt6 更新了PyQt5 MessageBox的用法,我在使用的时候发现,PyQt6没有MessageBox.Yes
或MessageBox.No
的用法
我在查看了弹窗返回的内容时发现,当点击按钮Yes的时候,返回回来的是<enum StanderButton.Yes>
无法完成判断的需求,我想到一个解决的方法是,将返回来的内容直接变成字符串的方式,再if
判断执行就行了
我之前的代码和结果:
try:
reply = QMessageBox.question(self, '信息提示', '确定删除内容?')
#reply = str(reply)
print(reply)
print(type(reply))
if reply == 'StandardButton.Yes':
del_row_sql = f'delete from integral_db where id={id}'
cur.execute(del_row_sql)
conn.commit()
else:
return
except Exception as e:
print(e)
输出结果:
我之后的代码和结果:
try:
reply = QMessageBox.question(self, '信息提示', '确定删除内容?')
reply = str(reply)
print(reply)
print(type(reply))
if reply == 'StandardButton.Yes':
del_row_sql = f'delete from integral_db where id={id}'
cur.execute(del_row_sql)
conn.commit()
else:
return
except Exception as e:
print(e)
总结:最关键的问题是改变返回结果的字符类型,再判断就OK了
有啥不明白的,欢迎留言!