我有以下代码在我的主窗口中工作,但我需要在弹出窗口中复制它。运行时它不会进入处理程序 def,我不知道为什么。我已经尝试了我能想到的一切。有人可以告诉我我做错了什么吗?
from PyQt4 import QtGui, QtCore
import sys
CurrentTime = 0
class widgetWindow(QtGui.QWidget):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self,parent)
super(widgetWindow, self).__init__()
widgetWindow.start(self)
def start(self):
window = QtGui.QMainWindow(self)
window.setAttribute(QtCore.Qt.WA_DeleteOnClose)
CentralWidget = QtGui.QWidget()
timeSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
CentralWidgetLayout = QtGui.QHBoxLayout()
VBox = QtGui.QVBoxLayout()
CentralWidgetLayout.addWidget(timeSlider)
VBox.addLayout(CentralWidgetLayout)
CentralWidget.setLayout(VBox)
window.setCentralWidget(CentralWidget)
timeSlider.setValue(0)
window.show()
self.runTimer()
def runTimer(self):
timer = QtCore.QTimer()
timer.timeout.connect(self.updateTime)
timer.start(1000)
def updateTime(self):
global CurrentTime
CurrentTime = CurrentTime + 1
print("Current Timer = ", CurrentTime)
def main():
app = QtGui.QApplication(sys.argv)
win = widgetWindow()
win.show()
win.resize(800,450)
sys.exit(app.exec_())
if __name__ == '__main__':
main()