from PyQt4 import QtGui
from PyQt4 import QtCore
class Widget(QtGui.QWidget):
def __init__(self, parent=None):
super(Widget, self).__init__()
layout = QtGui.QVBoxLayout(self)
self.pb = QtGui.QProgressBar()
self.pb.setMaximum(100)
self.pb.setMinimum(0)
self.pb.setValue(0)
layout.addWidget(self.pb)
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.on_timer)
self.timer.start(1000)
def on_timer(self):
current_value = self.pb.value() + 1
self.pb.setValue(current_value)
if current_value == 100:
self.timer.stop()
if __name__ == '__main__':
app = QtGui.QApplication([])
w = Widget()
w.show()
app.exec()
from PyQt4 import QtGui, Qt
class MyLabel(QtGui.QLabel):
clicked = Qt.pyqtSignal(str)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def mousePressEvent(self, *args, **kwargs):
self.clicked.emit(self.text())
return QtGui.QLabel.mousePressEvent(self, *args, **kwargs)
class Main(QtGui.QWidget):
def __init__(self):
super().__init__()
layout = QtGui.QVBoxLayout(self)
for i in range(5):
label = MyLabel(self, "Label " + str(i))
label.clicked.connect(self.set_title)
layout.addWidget(label)
self.resize(300, 300)
def set_title(self, label):
self.setWindowTitle(label)
if __name__ == '__main__':
app = Qt.QApplication([])
m = Main()
m.show()
app.exec()
from PyQt5 import Qt
class ExampleWidget(Qt.QWidget):
def __init__(self):
super().__init__()
layout = Qt.QVBoxLayout(self)
layout.addWidget(Qt.QLabel("Label"))
layout.addWidget(Qt.QLineEdit("LineEdit"))
layout.addWidget(Qt.QPushButton("PushButton"))
pb = Qt.QProgressBar()
pb.setValue(66)
layout.addWidget(pb)
if __name__ == '__main__':
app = Qt.QApplication([])
w = ExampleWidget()
w.show()
app.exec()
from PyQt4.QtGui import QWidget, QVBoxLayout, QPushButton, QProgressBar, QApplication
from PyQt4.QtCore import QThread, pyqtSignal
import time
class SomeThread(QThread):
progressed = pyqtSignal(int)
def __init__(self):
super().__init__()
def run(self):
for i in range(1, 11):
self.progressed.emit(i)
time.sleep(0.5)
class App(QWidget):
def __init__(self):
super().__init__()
vbox = QVBoxLayout()
self.pBar = QProgressBar()
self.pBar.setMaximum(10)
vbox.addWidget(self.pBar)
self.button = QPushButton("Start")
vbox.addWidget(self.button)
self.thread = None
self.setLayout(vbox)
self.button.clicked.connect(self.on_button)
def on_button(self):
if not self.thread:
self.thread = SomeThread()
self.thread.progressed.connect(self.on_progress)
self.thread.finished.connect(self.on_finished)
self.thread.start()
def on_progress(self, value):
self.pBar.setValue(value)
def on_finished(self):
self.thread.progressed.disconnect(self.on_progress)
self.thread.finished.disconnect(self.on_finished)
self.thread = None
if __name__ == '__main__':
qApp = QApplication([])
app = App()
app.show()
qApp.exec()
class ORGH_widget(Qt.QWidget):
def __init__(self, parent=None):
super(ORGH_widget, self).__init__(parent)
self.maindialog = ORGH_app(None)
self.layout = Qt.QVBoxLayout(self)
self.layout.addWidget(self.maindialog)
self.maindialog.show()
# self.exec_loop()
def keyPressEvent(self, e):
if e.key() == Qt.Qt.Key_Escape:
self.close()
class ORGH_app(Qt.QMainWindow):
def __init__(self, parent):
super(ORGH_app, self).__init__()
self.form = Ui_Form()
self.form.setupUi(self)
self._connectSlots()
def _connectSlots(self):
self.form.pushButton.clicked.connect(self._slotAddClicked)
def _slotAddClicked(self):
text = self.form.lineEdit.text()
if len(text):
# tvi = Qt.QTableViewItem(self.form.tableView)
# tvi.setText(0, text)
self.form.lineEdit.clear()
if __name__ == "__main__":
app = Qt.QApplication(sys.argv)
main = ORGH_app(None)
main.show()
sys.exit(app.exec())
import sys
from PyQt5.Qt import QVBoxLayout, QLabel, QDialog, QDialogButtonBox, Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
class InfoDialog(QDialog):
def __init__(self, info_str, parent=None):
super(InfoDialog, self).__init__(parent)
layout = QVBoxLayout(self)
layout.addWidget(QLabel(info_str))
buttons = QDialogButtonBox(QDialogButtonBox.Ok, Qt.Horizontal, self)
buttons.accepted.connect(self.accept)
layout.addWidget(buttons)
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
exitAction = QAction(QIcon('RM.png'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.triggered.connect(qApp.quit)
infoAction = QAction(QIcon(), "Info", self)
infoAction.triggered.connect(self.onInfoAction)
self.toolbar = self.addToolBar('Exit')
self.toolbar.addAction(exitAction)
self.toolbar.addAction(infoAction)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Toolbar')
self.show()
def onInfoAction(self):
w = InfoDialog("Some information", self)
w.exec_()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
from PyQt4.QtCore import *
from PyQt4 import QtGui
class HelloPython(QtGui.QWidget):
def __init__(self, parent=None):
super(HelloPython, self).__init__(parent)
helloLabel = QtGui.QLabel("Say Hello To PyQT!")
helloLineEdit = QtGui.QLineEdit()
mainLayout = QtGui.QGridLayout()
mainLayout.addWidget(helloLabel, 0, 0)
mainLayout.addWidget(helloLineEdit, 0, 1)
self.setLayout(mainLayout)
self.setWindowTitle("My Python App")
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
helloPythonWidget = HelloPython()
helloPythonWidget.show()
sys.exit(app.exec_())
from distutils.core import setup
import py2exe
setup(windows=['main.py'], options={"py2exe": {"bundle_files": 1, "compressed": True, "includes": ["sip"]}})