python PyQt信号和插槽的连接
发布时间:2024-06-24 13:50:41

1、用户点击时,需要将信号与内置插槽连接起来,使菜单选项和工具栏能够启动。
2、QAction物体可以发出各种信号。triggered()与插槽连接。
菜单和工具栏中最常用的信号是.triggered()。每次用户点击菜单选项或工具栏按钮,都会发出此信号。
实例
classWindow(QMainWindow):
#Snip...
defnewFile(self):
#Logicforcreatinganewfilegoeshere...
self.centralWidget.setText("<b>File>New</b>clicked")
defopenFile(self):
#Logicforopeninganexistingfilegoeshere...
self.centralWidget.setText("<b>File>Open...</b>clicked")
defsaveFile(self):
#Logicforsavingafilegoeshere...
self.centralWidget.setText("<b>File>Save</b>clicked")
defcopyContent(self):
#Logicforcopyingcontentgoeshere...
self.centralWidget.setText("<b>Edit>Copy</b>clicked")
defpasteContent(self):
#Logicforpastingcontentgoeshere...
self.centralWidget.setText("<b>Edit>Paste</b>clicked")
defcutContent(self):
#Logicforcuttingcontentgoeshere...
self.centralWidget.setText("<b>Edit>Cut</b>clicked")
defhelpContent(self):
#Logicforlaunchinghelpgoeshere...
self.centralWidget.setText("<b>Help>HelpContent...</b>clicked")
defabout(self):
#Logicforshowinganaboutdialogcontentgoeshere...
self.centralWidget.setText("<b>Help>About...</b>clicked")以上是python PyQT信号与插槽的连接方式,希望对大家有所帮助。更多Python学习指导:python基础教程
本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。
