2
考慮下面的最小例子。它完美,直到我去掉下面幾行:mpylayer,PyQt4和lineEdit
# self.mainwi = QtGui.QWidget(self)
# self.lineEdit1 = QtGui.QLineEdit(self.mainwi)
# self.setCentralWidget(self.lineEdit1)
如果這些線是未加註釋,我可以寫在LineEdit場的文本,但按鈕沒有反應。任何想法它有什麼問題,如何解決這個問題?
我應該補充一點,我是編程python的絕對初學者。
#!/usr/bin/python
import mpylayer
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui
class DmplayerGUI(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.dirty = False
self.mp = mpylayer.MPlayerControl()
#Toolbar
## items
### Play
self.play = QtGui.QAction(QtGui.QIcon('icons/play_32.png'), 'Play', self)
self.play.setShortcut('Ctrl+A')
self.connect(self.play, QtCore.SIGNAL('triggered()'), self.DPlay)
### Pause
self.pause = QtGui.QAction(QtGui.QIcon('icons/pause_32.png'), 'Pause', self)
self.pause.setShortcut('Ctrl+P')
self.connect(self.pause, QtCore.SIGNAL('triggered()'), self.DPause)
## toolbar
self.toolbar = self.addToolBar('Toolbar')
self.toolbar.addAction(self.play)
self.toolbar.addAction(self.pause)
# self.mainwi = QtGui.QWidget(self)
# self.lineEdit1 = QtGui.QLineEdit(self.mainwi)
# self.setCentralWidget(self.lineEdit1)
# play
def DPlay(self):
self.mp.loadfile('video.mp4')
# pause
def DPause(self):
self.mp.pause(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
dp = DmplayerGUI()
dp.show()
sys.exit(app.exec_())
你爲什麼不把自己的'self.mainwi'設置爲你的中央控件? –
@ dex19dt我認爲這是一個絕對的初學者錯誤:-) – student