pyqt4 测试
时间:2006-08-13 来源:kai0200
PyQt4 学习
>>> import sys
>>> from PyQt4 import QtCore, QtGui
>>> app=QtGui.QApplication(sys.argv)
>>> button = QtGui.QPushButton("Hello Word",None)
>>> button.show() 上面几行就可以显示,研究了几天发现资料太少,而且qt3的非常多! 这里借用一个limodou的学习记录 的例子不过是pyqt3的弄了半天改成pyqt4的,不过好像single slot 的实现3 4 好像不一样 1 import sys
2 from qt import *
3
4 class HelloButton(QPushButton):
5
6 def __init__(self, *args):
7 QPushButton.__init__(self, *args)
8 self.setText("Hello World")
9
10 class HelloWindow(QMainWindow):
11
12 def __init__(self, *args):
13 QMainWindow.__init__(self, *args)
14 self.button=HelloButton(self)
15 self.setCentralWidget(self.button)
16
17 def main(args):
18 app=QApplication(args)
19 win=HelloWindow()
20 win.show()
21 app.connect(app, SIGNAL("lastWindowClosed()"),
22 app, SLOT("quit()"))
23 app.exec_loop()
24
25 if __name__=="__main__":
26 main(sys.argv) pyqt4 代码
>>> from PyQt4 import QtCore, QtGui
>>> app=QtGui.QApplication(sys.argv)
>>> button = QtGui.QPushButton("Hello Word",None)
>>> button.show() 上面几行就可以显示,研究了几天发现资料太少,而且qt3的非常多! 这里借用一个limodou的学习记录 的例子不过是pyqt3的弄了半天改成pyqt4的,不过好像single slot 的实现3 4 好像不一样 1 import sys
2 from qt import *
3
4 class HelloButton(QPushButton):
5
6 def __init__(self, *args):
7 QPushButton.__init__(self, *args)
8 self.setText("Hello World")
9
10 class HelloWindow(QMainWindow):
11
12 def __init__(self, *args):
13 QMainWindow.__init__(self, *args)
14 self.button=HelloButton(self)
15 self.setCentralWidget(self.button)
16
17 def main(args):
18 app=QApplication(args)
19 win=HelloWindow()
20 win.show()
21 app.connect(app, SIGNAL("lastWindowClosed()"),
22 app, SLOT("quit()"))
23 app.exec_loop()
24
25 if __name__=="__main__":
26 main(sys.argv) pyqt4 代码
#!/usr/bin/env python
import sys
from PyQt4 import QtCore, QtGui
class HelloButton(QtGui.QPushButton):
def __init__(self,parent=None):
QtGui.QPushButton.__init__(self, parent)
self.setText("Hello World")
class HelloWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QMainWindow.__init__(self,parent)
self.button=HelloButton(self)
self.setCentralWidget(self.button)
def main(args):
app=QtGui.QApplication(args)
win=HelloWindow()
win.show()
app.connect(app, QtCore.SIGNAL("lastWindowClosed()"),
app, QtCore.SLOT("quit()"))
app.exec_()
if __name__=="__main__":
main(sys.argv) 不过还是又些问题!
import sys
from PyQt4 import QtCore, QtGui
class HelloButton(QtGui.QPushButton):
def __init__(self,parent=None):
QtGui.QPushButton.__init__(self, parent)
self.setText("Hello World")
class HelloWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QMainWindow.__init__(self,parent)
self.button=HelloButton(self)
self.setCentralWidget(self.button)
def main(args):
app=QtGui.QApplication(args)
win=HelloWindow()
win.show()
app.connect(app, QtCore.SIGNAL("lastWindowClosed()"),
app, QtCore.SLOT("quit()"))
app.exec_()
if __name__=="__main__":
main(sys.argv) 不过还是又些问题!
#!/usr/bin/env python
import sys
from PyQt4 import QtCore, QtGui
class HelloButton(QtGui.QPushButton):
def __init__(self,parent=None):
QtGui.QPushButton.__init__(self, parent)
self.setText("Hello World")
class HelloWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QMainWindow.__init__(self,parent)
self.button=HelloButton(self)
self.setCentralWidget(self.button)
def main(args):
app=QtGui.QApplication(args)
win=HelloWindow()
win.connect(win.button,QtCore.SIGNAL("clicked()"),win,QtCore.SLOT("close()"))
win.show()
app.connect(app, QtCore.SIGNAL("lastWindowClosed()"),
app, QtCore.SLOT("quit()"))
app.exec_()
if __name__=="__main__":
main(sys.argv) 问了一下单位搞python的哥们帮我该了一下,不过还是不是很清楚!有点郁闷!
主要就是这句话
win.connect(win.button,QtCore.SIGNAL("clicked()"),win,QtCore.SLOT("close()"))
win本身就是一个button 为什么第一个对象还要写win.button 呢还有就是SIGNAL 和 SLOT 具体怎么用还是不理解!
import sys
from PyQt4 import QtCore, QtGui
class HelloButton(QtGui.QPushButton):
def __init__(self,parent=None):
QtGui.QPushButton.__init__(self, parent)
self.setText("Hello World")
class HelloWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QMainWindow.__init__(self,parent)
self.button=HelloButton(self)
self.setCentralWidget(self.button)
def main(args):
app=QtGui.QApplication(args)
win=HelloWindow()
win.connect(win.button,QtCore.SIGNAL("clicked()"),win,QtCore.SLOT("close()"))
win.show()
app.connect(app, QtCore.SIGNAL("lastWindowClosed()"),
app, QtCore.SLOT("quit()"))
app.exec_()
if __name__=="__main__":
main(sys.argv) 问了一下单位搞python的哥们帮我该了一下,不过还是不是很清楚!有点郁闷!
主要就是这句话
win.connect(win.button,QtCore.SIGNAL("clicked()"),win,QtCore.SLOT("close()"))
win本身就是一个button 为什么第一个对象还要写win.button 呢还有就是SIGNAL 和 SLOT 具体怎么用还是不理解!
相关阅读 更多 +