pyside6界面开发笔记(06)

程序入口模板:pyside6界面开发笔记——模板框架
回顾:
标签控件
信号与槽

消息框控件

各种类型的消息框

类型方法
询问QMessageBox.question()
信息QMessageBox.information()
警告QMessageBox.waring()
错误QMessageBox.critical()
关于QMessageBox.about()
class Window(QWidget):

    def __init__(self):
        super(Window,self).__init__()
        button=QPushButton('信息框')
        button.clicked.connect(self.show_info)

        h_layout=QHBoxLayout()
        h_layout.addWidget(button)
        self.setLayout(h_layout)

    def show_info(self):
        QMessageBox.information(self,'标题','内容',QMessageBox.Yes)
        """
        QMessageBox提供了以下常用按钮:
        QMessageBox.Ok
        QMessageBox.Yes
        QMessageBox.No
        QMessageBox.Close
        QMessageBox.Open
        """

与消息框交互

class Window(QWidget):

    def __init__(self):
        super(Window,self).__init__()
        self.button=QPushButton('点我')
        self.button.clicked.connect(self.change_text)

        h_layout=QHBoxLayout()
        h_layout.addWidget(self.button)
        self.setLayout(h_layout)

    def change_text(self):
        choice=QMessageBox.question(self,'询问框','要改变文字吗?',
                                    QMessageBox.Yes|QMessageBox.No)

        if choice==QMessageBox.Yes:
            self.button.setText('文字改变')

编写带有中文按钮的消息框

class QuestionMessageBox(QMessageBox):      # 自定义消息框
    def __init__(self,parent,title,content):
        super(QuestionMessageBox,self).__init__(parent)

        self.setWindowTitle(title)
        self.setText(content)
        self.setIcon(QMessageBox.Question)
        """
        QMessageBox.NoIcon:错误
        QMessageBox.Question:问号
        QMessageBox.Information:信息
        QMessageBox.Warning:警告
        QMessageBox.Critical:错误
        """
        self.addButton('是',QMessageBox.YesRole)
        self.addButton('否',QMessageBox.NoRole)
        """
        QMessageBox.AcceptRole:ok
        QMessageBox.RejectRole:cancel
        QMessageBox.YesRole:yes
        QMessageBox.NoRole:no
        """
        
class Window(QWidget):

    def __init__(self):
        super(Window,self).__init__()
        self.button=QPushButton('点我')
        self.button.clicked.connect(self.change_text)

        h_layout=QHBoxLayout()
        h_layout.addWidget(self.button)
        self.setLayout(h_layout)
        
    def change_text(self):
        msb_box=QuestionMessageBox(self,'标题','是否改变文本?')
        msb_box.exec()
        
        if msb_box.clickedButton().text()=='是':
            self.button.setText('文字改变')

Pyside6是一个用于创建跨平台图形用户界面(GUI)的Python库。当你在使用Pyside6时,可能会遇到一些界面显示异常的情况。这些异常可能包括但不限于界面元素错位、颜色异常、布局问题等。 解决Pyside6界面显示异常的方法有以下几种: 1. 检查代码逻辑:首先,你需要检查你的代码逻辑是否正确。确保你正确地设置了界面元素的位置、大小和属性。检查你的布局管理器是否正确地放置了界面元素。 2. 检查样式表:Pyside6支持使用样式表来自定义界面的外观。如果你使用了样式表,那么可能是样式表中的某些属性设置不正确导致了界面显示异常。请检查你的样式表并确保其中的属性设置正确。 3. 检查版本兼容性:Pyside6可能与不同版本的Python和操作系统存在兼容性问题。请确保你使用的Pyside6版本与你的Python版本和操作系统版本兼容。 4. 更新Pyside6:如果你使用的是旧版本的Pyside6,可能存在已知的界面显示异常问题。尝试更新到最新版本的Pyside6,以获得修复了这些问题的新功能和改进。 5. 查找文档和社区支持:如果以上方法都无法解决你的问题,建议查阅Pyside6的官方文档和社区支持。在官方文档中,你可以找到更多关于Pyside6的使用方法和常见问题的解答。同时,社区支持也是一个很好的资源,你可以在社区中提问并获得其他开发者的帮助和经验分享。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值