意外类型“StandardButton”PyQt5 messagebox

2024-09-28 21:15:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试只弹出一个消息框,其中只有单击“确定”的选项

代码如下:

show_message_box(QMessageBox.Critical,
                 "ERREUR",
                 "Il n'est pas possible de bloquer cette plage horraire pour " + employee, QMessageBox.Ok)

我有个错误setInformativeText(Self,str): argument 1 has unexpected type 'StandardButton'

我的另一个msgbox工作正常,但它们有yesno选项。这个,我只想要ok选项

谢谢你的帮助


Tags: 代码box消息message选项showdepas
1条回答
网友
1楼 · 发布于 2024-09-28 21:15:19

试试看:

import sys
from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.error_popup()

    def error_popup(self):
        
        employee = 'Name 1'
        
        QMessageBox.critical(
            self,
            "ERREUR",
            f"Il n'est pas possible de bloquer cette plage horraire pour <b>{employee}</b>", 
            QMessageBox.Ok
        )
                 
        
if __name__ == "__main__":
    App = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(App.exec_())        

enter image description here

相关问题 更多 >