湖北二师网站建设排名,微站和网站数据,网站建设公司怎样,定制专业app开发文章目录报错内容鼠标事件演示报错内容
在pyside图形界面应用程序开发过程中,通常只允许运行一个实例 假设您重复执行程序A,那么可能会导致一些意向不到的错误并且,从python反馈的信息不容易判断错误的真正来源
鼠标事件演示 下面是一段演示pyside6的鼠标事件mouseEvent对象…
文章目录报错内容鼠标事件演示报错内容
在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创建的窗口,控制台的内容被情况,同时又弹出了一个一样的到窗口我在这个窗口上试验就没有类似的报错