当前位置: 首页 > news >正文

pyside6@Mouse events实例@QApplication重叠导致的报错@keyboardInterrupt

文章目录

    • 报错内容
    • 鼠标事件演示

报错内容

  • 在pyside图形界面应用程序开发过程中,通常只允许运行一个实例
    • 假设您重复执行程序A,那么可能会导致一些意向不到的错误
    • 并且,从python反馈的信息不容易判断错误的真正来源

鼠标事件演示

  • 下面是一段演示pyside6的鼠标事件mouseEvent对象的相关api

    • import sysfrom PySide6.QtCore import Qt
      from PySide6.QtWidgets import QMainWindow, QApplication, QLabelclass MainWindow(QMainWindow):def __init__(self):super().__init__()self.label = QLabel("Click in this window")self.setCentralWidget(self.label)def mousePressEvent(self, e):if e.button() == Qt.LeftButton:# handle the left-button press in hereself.label.setText("mousePressEvent LEFT")elif e.button() == Qt.MiddleButton:# handle the middle-button press in here.self.label.setText("mousePressEvent MIDDLE")elif e.button() == Qt.RightButton:# handle the right-button press in here.self.label.setText("mousePressEvent RIGHT")def mouseReleaseEvent(self, e):if e.button() == Qt.LeftButton:self.label.setText("mouseReleaseEvent LEFT")elif e.button() == Qt.MiddleButton:self.label.setText("mouseReleaseEvent MIDDLE")elif e.button() == Qt.RightButton:self.label.setText("mouseReleaseEvent RIGHT")def mouseDoubleClickEvent(self, e):if e.button() == Qt.LeftButton:self.label.setText("mouseDoubleClickEvent LEFT")elif e.button() == Qt.MiddleButton:self.label.setText("mouseDoubleClickEvent MIDDLE")elif e.button() == Qt.RightButton:self.label.setText("mouseDoubleClickEvent RIGHT")if __name__ == '__main__':# Create the Qt Applicationapp = QApplication(sys.argv)# Create and show the form|mainwindow = MainWindow()mainwindow.resize(400, 400)mainwindow.show()# Run the main Qt loopsys.exit(app.exec())
  • 上面的代码时可以正常工作的

    • 当我初次运行的时候没有看到弹出窗口(实际上根据电源策略,需要一点时间来启动窗口)
    • 然后我急忙有运行了一遍程序,python并没有立即给我报错
    • 此时窗口已经弹出来了,我点击了以下窗口想试试鼠标事件的处理过程,于是就给我弹出错误KeyboardInterrupt的提示
    • 然而我只是点击一下鼠标,并没有敲击键盘
    • 我关闭掉当前的pyside创建的窗口,控制台的内容被情况,同时又弹出了一个一样的到窗口
    • 我在这个窗口上试验就没有类似的报错
  • 在这里插入图片描述

http://www.lryc.cn/news/38932.html

相关文章:

  • 订单30分钟未支付自动取消怎么实现?
  • < 开源项目框架:推荐几个开箱即用的开源管理系统 - 让开发不再复杂 >
  • 内网渗透-基础环境
  • Go语言学习的第一天(对于Go学习的认识和工具选择及环境搭建)
  • C和C++到底有什么关系
  • 14个Python处理Excel的常用操作,非常好用
  • async/await 用法
  • 好意外,发现永久免费使用的云服务器
  • VSCode使用技巧,代码编写效率提升2倍以上!
  • SQL执行过程详解
  • 【物联网NodeJs-5天学习】第四天存储篇⑤ ——PM2,node.js应用进程管理器
  • 【C++学习】【STL】deque容器
  • 当 App 有了系统权限,真的可以为所欲为?
  • vue3.js的介绍
  • 【Three.js】shader特效 能量盾
  • 【6000字长文】需求评审总是被怼?强烈推荐你试试这三招
  • Hive介绍及DDL
  • Simulink 自动代码生成电机控制:在某国产ARM0定点MCU上实现自动代码生成无感电机控制
  • MySQL基本查询
  • 你需要知道的 7 个 Vue3 技巧
  • 行政区划获取
  • 让ChatGPT介绍一下ChatGPT
  • 【Redis】Redis 主从复制 + 读写分离
  • 2023届秋招,鬼知道我经历了什么
  • ChatGPT助力校招----面试问题分享(一)
  • CSS媒体查询@media (prefers-color-scheme:dark)判断系统白天黑夜模式
  • 运行YOLOv8实现识别
  • 如何在Linux中优雅的使用 head 命令,用来看日志简直溜的不行
  • Nginx.conf 配置详解
  • 剖析NLP历史,看chatGPT的发展