我有方法getCurrentDate;此方法必须返回当前显示的月份。
# coding: utf-8
import sys
from PyQt4 import QtCore, QtGui
class Window(QtGui.QCalendarWidget):
def __init__(self):
QtGui.QCalendarWidget.__init__(self)
self.resize(300, 300)
self.connect(self, QtCore.SIGNAL('currentPageChanged()'), self.getCurrentDate)
print self.getCurrentDate()
def getCurrentDate(self):
return self.monthShown()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
gui = Window()
gui.show()
sys.exit(app.exec_())当我调用getCurrentDate时,它返回当前值(例如2 ),但是当我将显示更改为下个月时,方法将什么都不返回。为什么?
发布于 2014-02-11 09:53:33
你需要改变这一点:
self.connect(self, QtCore.SIGNAL('currentPageChanged()'), self.getCurrentDate)至:
self.connect(self, QtCore.SIGNAL('currentPageChanged(int,int)'), self.getCurrentDate)这将返回正确的值,如果要打印值,则需要在函数中放置一个print语句:
def getCurrentDate(self):
print self.monthShown()
return self.monthShown()https://stackoverflow.com/questions/21697898
复制相似问题