PyQt 第一个程序 “Hello World”
2009-07-12 23:21
507 查看
# Every Qt application needs a QApplication object. sys.argv are the command line arguments.
# QApplication needs them so it can handle options, like -help (try it) a=qt.QApplication(sys.argv)
# We create a button called w. It says "Hello World" and has no parent (None as second argument).
# Not having a parent means it's a top-level window, so it's not "inside" anything.
# In other words: a window with a button as its whole content. w=qt.QPushButton("Hello World",None)
# Show the button w.show()
# Enter the application loop. That means the application will start running,
# and will start to interact with the user.
# Since there is nothing to interact with, no user-input can stop the application from 'running'.
# The fully functional one below doesn't have this limitation and uses the main concept of PyQT. a.exec_loop() }}}
#import qt,sys
#a=qt.QApplication(sys.argv)
#w=qt.QPushButton("Hello World",None)
# Here the differences to the trivial one above may be seen, using QT's signal and slot features:
# We connect the clicked() signal to the button's "close" slot (method).
# Whenever you click on the button, it emits the signal. Then every slot that is
# connected to that signal gets called. In this case, only w.close w.connect(w,qt.SIGNAL("clicked()"),w.close)
# We make w the main widget of the application. That means that when w is closed
# The application exits. If we didn't do this, we would have to call a.quit()
# to make it end. a.setMainWidget(w)
#w.show()
#a.exec_loop()
import sys;
from PyQt4 import QtGui,QtCore
from PyQt4.QtCore import *;
from PyQt4.QtGui import *;
class MainWindow(QDialog):
def __init__(self, parent=None):
#QMainWindow.__init__(self, parent)
#self.setWindowTitle(self.tr("Hello World From PyQt!"))
btnpush.connect(btnpush, SIGNAL("clicked()"), btnpush.close)
if __name__ == "__main__":
app = QApplication(sys.argv)
btnpush = QPushButton("Hello World", None)
btnpush.show()
#mainwindow = MainWindow()
#mainwindow.show()
sys.exit(app.exec_())
【
import sys;
from PyQt4.QtCore import *;
from PyQt4.QtGui import *;
class MainWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.setWindowTitle(self.tr("Hello World From PyQt!"))
if __name__ == "__main__":
app = QApplication(sys.argv)
mainwindow = MainWindow()
mainwindow.show()
sys.exit(app.exec_())
】
# QApplication needs them so it can handle options, like -help (try it) a=qt.QApplication(sys.argv)
# We create a button called w. It says "Hello World" and has no parent (None as second argument).
# Not having a parent means it's a top-level window, so it's not "inside" anything.
# In other words: a window with a button as its whole content. w=qt.QPushButton("Hello World",None)
# Show the button w.show()
# Enter the application loop. That means the application will start running,
# and will start to interact with the user.
# Since there is nothing to interact with, no user-input can stop the application from 'running'.
# The fully functional one below doesn't have this limitation and uses the main concept of PyQT. a.exec_loop() }}}
#import qt,sys
#a=qt.QApplication(sys.argv)
#w=qt.QPushButton("Hello World",None)
# Here the differences to the trivial one above may be seen, using QT's signal and slot features:
# We connect the clicked() signal to the button's "close" slot (method).
# Whenever you click on the button, it emits the signal. Then every slot that is
# connected to that signal gets called. In this case, only w.close w.connect(w,qt.SIGNAL("clicked()"),w.close)
# We make w the main widget of the application. That means that when w is closed
# The application exits. If we didn't do this, we would have to call a.quit()
# to make it end. a.setMainWidget(w)
#w.show()
#a.exec_loop()
import sys;
from PyQt4 import QtGui,QtCore
from PyQt4.QtCore import *;
from PyQt4.QtGui import *;
class MainWindow(QDialog):
def __init__(self, parent=None):
#QMainWindow.__init__(self, parent)
#self.setWindowTitle(self.tr("Hello World From PyQt!"))
btnpush.connect(btnpush, SIGNAL("clicked()"), btnpush.close)
if __name__ == "__main__":
app = QApplication(sys.argv)
btnpush = QPushButton("Hello World", None)
btnpush.show()
#mainwindow = MainWindow()
#mainwindow.show()
sys.exit(app.exec_())
【
import sys;
from PyQt4.QtCore import *;
from PyQt4.QtGui import *;
class MainWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.setWindowTitle(self.tr("Hello World From PyQt!"))
if __name__ == "__main__":
app = QApplication(sys.argv)
mainwindow = MainWindow()
mainwindow.show()
sys.exit(app.exec_())
】
相关文章推荐
- PyQt 第一个程序 “Hello World”
- 在Cent OS7下写第一个QT程序:Hello World!
- “Hello World”—— 第一个汇编程序
- 用Free Pascal IDE编写第一个程序Pascal版的hello world
- 用记事本写java的第一个程序hello world 以及eclipse的使用方法
- object-c第一个程序:Hello World
- 基于Xcode4开发第一个iPhone程序:“Hello World”
- 使用PyQt来编写第一个Python GUI程序
- PyQt5(1)——安装环境和创建第一个窗口程序
- C++ Qt 02:第一个Qt程序,Hello World
- 第一个C#程序Hello World
- Qt on Android---第一个程序Hello World
- 第一个Java程序示例——Hello World!
- 第一个clojure 的hello world程序
- objective_c第一个程序Hello World
- QT的第一个程序HELLO WORLD
- windows azure 第一个程序Hello World
- 我的第一个C#程序--Hello world
- [PyQt]第一个测试程序
- Pyqt5系列(二 )-第一个PyQt程序