我有一個主窗口,我叫子窗口(彈出),我無法接入高清錄入(個體經營),它給了我一個屬性錯誤:無法在子窗口存取權限一個「高清」 - 「主窗口對象有沒有屬性‘錄入’」從一個按鈕
AttributeError: 'MainWindow' object has no attribute 'updateTime'
如果我參加了主窗口部分能正常工作,所以我真的不明白是什麼問題。任何幫助將不勝感激。
from PyQt4 import QtGui, QtCore
from PyQt4 import *
from PyQt4.QtCore import *
import sys
CurrentTime = 0
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.central = QtGui.QWidget(self)
self.setCentralWidget(self.central)
self.hboxPB = QtGui.QHBoxLayout()
self.vboxPB = QtGui.QVBoxLayout()
self.MyButton = QtGui.QPushButton(self.central)
self.MyButton.setText("Push Me")
self.hboxPB.addWidget(self.MyButton)
self.vboxPB.addLayout(self.hboxPB)
self.MyButton.resize(90,90)
self.MyButton.clicked.connect(lambda: widgetWindow.start(self))
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()
self.timeSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
CentralWidgetLayout = QtGui.QHBoxLayout()
VBox = QtGui.QVBoxLayout()
CentralWidgetLayout.addWidget(self.timeSlider)
VBox.addLayout(CentralWidgetLayout)
CentralWidget.setLayout(VBox)
window.setCentralWidget(CentralWidget)
window.show()
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.updateTime)
self.timer.start(1000)
def updateTime(self):
global CurrentTime
CurrentTime = CurrentTime + 1
self.timeSlider.setValue(CurrentTime)
def main():
app = QtGui.QApplication(sys.argv)
win = MainWindow()
win.show()
win.resize(800,450)
sys.exit(app.exec_())
if __name__ == '__main__':
main()
非常感謝你!!!!你不知道你剛剛救了我多少時間。 – user3723727
@geochet thnx進行編輯! – dsgdfg