Start an interactive python session by executing python in a shell:
$> python Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>Let's create a simle top-level window (I wont add the '>>>' in case you would like to copy/paste the code):
from PyQt4.QtCore import * from PyQt4.QtGui import * app = QApplication() window = QWidget() window.resize(400, 300) window.show()Now you should have a window similar to the screen shot below:
Ok, let's create a push button:
button = QPushButton("Click Me!", window)Hmm, no button shows up... Why? Well, that's because we need to make it visible after we have added it to the window:
button.show()Ahh, sweet! We have added the button to the window interactively:
layout = QHBoxLayout(window) layout.addWidget(button)
And finally, let's see how 'layout.addStretch()' affects the layout:
def mySlot(): print "Button Clicked" button.clicked.connect(mySlot)As you can see, it's an easy way to try out thing in Qt.
Thanks for reading!