#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class Example(QtGui.QMainWindow):
def __init__(self):
super(Example, self).__init__();
self.initUI()
def initUI(self):
self.button = QtGui.QPushButton("print clicked",self)
self.clicked='not_clicked'
self.button.clicked.connect(lambda opt='clicked': self.option(opt))
def option(self,opt):
self.clicked=opt
print opt
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())
if __name__=='__main__':
main()
考虑这段代码。现在,当我点击“打印点击”按钮时。'False' 被打印(在选项函数中)。为什么会这样?