【发布时间】:2016-01-10 21:45:44
【问题描述】:
我有一个带有按钮的工具栏,该按钮应该启用/禁用显示一些图片的标签,我该怎么做? 我创建了一个我调用的函数,但是当我运行代码时,我得到了这个:
File "saw_notes_027.py", line 41, in initUI
showHidePicture.triggered.connect(self.tbody.showPictures())
TypeError: argument 1 has unexpected type 'NoneType'
这里有一些代码:
class AppBase(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.tbody = Body(self)
self.setCentralWidget(self.tbody)
showHidePicture = QAction(QIcon('image20151027_123417794.jpg'), 'Show / Hide Picture', self)
showHidePicture.setShortcut('Ctrl+I')
showHidePicture.setStatusTip('Show / Hide Picture')
showHidePicture.triggered.connect(self.tbody.showPictures())
[...other code....]
toolbar = self.addToolBar('Picture')
toolbar.addAction(showHidePicture)
class Body(QWidget):
def __init__(self, parent):
super().__init__(parent)
self.initBody()
def initBody(self):
[...other code....]
self.grid.addWidget(self.label_exercise, 0, 0)
self.grid.addWidget(self.combo_exercise, 1, 0)
self.grid.addWidget(self.label_key, 0, 1)
self.grid.addWidget(self.combo_key, 1, 1)
self.grid.addWidget(self.label_font, 0, 2)
self.grid.addWidget(self.btn_font, 1, 2)
self.grid.addWidget(self.sld, 2, 0, 1, 3)
self.grid.addWidget(self.lcd, 2, 3)
self.grid.addWidget(self.label_note, 3, 0)
self.grid.addWidget(self.label_string, 3, 1)
self.grid.addWidget(self.label_finger, 3, 2)
self.grid.addWidget(self.btn_start, 4, 0)
self.grid.addWidget(self.btn_exit, 4, 1)
self.grid.addWidget(self.label_picture, 5, 0, 1, 6)
self.setLayout(self.grid)
self.active_pictures = False
def showPictures(self):
if self.active_pictures == False:
self.active_pictures = True
self.grid.addWidget(self.label_picture, 5, 0, 1, 3)
else:
self.active_pictures = False
self.grid.removeWidget(self.label_picture)
[...other code....]
谢谢大家。
我修复了我要离开的showHidePicture.triggered.connect(self.tbody.showPictures()) 行,以防其他人需要,我没有出现错误,但软件以有线方式运行,当我单击它时,它会显示/隐藏那些其他小部件:
self.grid.addWidget(self.label_note, 3, 0)
self.grid.addWidget(self.label_string, 3, 1)
self.grid.addWidget(self.label_finger, 3, 2)
self.grid.addWidget(self.btn_start, 4, 0)
self.grid.addWidget(self.btn_exit, 4, 1)
所以,我仍然需要你们的帮助;)
再次感谢。
【问题讨论】:
标签: image python-3.x qt5 picturebox pyqt5