Created
May 5, 2015 12:05
-
-
Save rbarzic/0cddb30c07dbc7f36956 to your computer and use it in GitHub Desktop.
A simple PtQt app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt4 import QtGui, QtCore | |
class SimpleGui(QtGui.QWidget): | |
""" | |
A simple PyQT gui example | |
""" | |
def __init__(self): | |
# create GUI | |
QtGui.QMainWindow.__init__(self) | |
self.setWindowTitle('SimpleGui ') | |
# Set the window dimensions | |
self.resize(400,100) | |
# vertical layout for widgets | |
self.grid = QtGui.QGridLayout() | |
self.setLayout(self.grid) | |
# Create a push button labelled 'choose' and add it to our layout | |
self.btn_b1 = QtGui.QPushButton('Button1', self) | |
self.grid.addWidget(self.btn_b1,1,1) | |
self.btn_b2 = QtGui.QPushButton('Button2', self) | |
self.grid.addWidget(self.btn_b2,1,2) | |
self.btn_b3 = QtGui.QPushButton('Button3', self) | |
self.grid.addWidget(self.btn_b3,1,3) | |
self.chk_t2h = QtGui.QCheckBox('CheckBox1') | |
self.grid.addWidget(self.chk_t2h,2,1) | |
self.chk_t2h.setChecked(True) | |
self.chk_verify = QtGui.QCheckBox('Verify') | |
self.grid.addWidget(self.chk_verify,3,1) | |
self.chk_verify.setChecked(True) | |
self.text = QtGui.QTextEdit(self) | |
self.grid.addWidget(self.text,4,0,10,6) | |
self.btn_b2.clicked.connect(self.b2_func) | |
self.btn_b1.clicked.connect(self.b1_func) | |
self.btn_b3.clicked.connect(self.b3_func) | |
def get_fname(self): | |
""" | |
Handler called when 'choose file' is clicked | |
""" | |
# When you call getOpenFileName, a file picker dialog is created | |
# and if the user selects a file, it's path is returned, and if not | |
# (ie, the user cancels the operation) None is returned | |
self.fname = QtGui.QFileDialog.getOpenFileName(self, 'Select file') | |
if self.fname: | |
self.filename.setText(self.fname) | |
else: | |
self.filename.setText('No file selected') | |
def b2_func(self): | |
print("-I- Button1") | |
pass | |
def b1_func(self): | |
print("-I- Button2") | |
pass | |
def b3_func(selfself): | |
print("-I- Button3") | |
pass | |
#def minimumSizeHint(self): | |
# return QtCore.QSize(600, 600) | |
if __name__ == "__main__": | |
app = QtGui.QApplication(sys.argv) | |
gui = SimpleGui() | |
gui.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment