├── .idea ├── misc.xml ├── modules.xml ├── pythonprogramming.iml ├── vcs.xml └── workspace.xml ├── LICENCE ├── README.md ├── pic.png ├── pyqt5_lesson_01.py ├── pyqt5_lesson_02.py ├── pyqt5_lesson_03.py ├── pyqt5_lesson_04.py ├── pyqt5_lesson_05.py ├── pyqt5_lesson_06.py ├── pyqt5_lesson_07.py ├── pyqt5_lesson_08.py ├── pyqt5_lesson_09.py ├── pyqt5_lesson_10.py ├── pyqt5_lesson_11.py ├── pyqt5_lesson_12.py ├── pyqt5_lesson_13.py ├── pyqt5_lesson_14.py └── pyqt5_lesson_15.py /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/pythonprogramming.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | gpl 39 | GPL 40 | GPL- 41 | 42 | 43 | MIT 44 | MIT- 45 | 46 | 47 | $PROJECT_DIR$ 48 | 49 | 50 | 51 | 53 | 54 | 73 | 74 | 75 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 103 | 104 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 139 | 140 | 156 | 157 | 173 | 174 | 185 | 186 | 204 | 205 | 223 | 224 | 244 | 245 | 266 | 267 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 304 | 305 | 306 | 307 | 1484162186771 308 | 312 | 313 | 1484162604230 314 | 319 | 320 | 1484257577663 321 | 326 | 327 | 1484258698130 328 | 333 | 334 | 1484318606650 335 | 340 | 341 | 1484318695049 342 | 347 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 376 | 377 | 378 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 vanbillemont kenny aka Kenwaldek 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pythonprogramming 2 | pythonprogramming.net PyQt4 to PyQt5 upgrade 3 | 4 | On pythonprogramming.net you can find an youtube lesson series of PyQt. 5 | The qt version used was PyQt4 in those lessons, here you can find the PyQt5 version of those lessons. 6 | There are some differents in the new version that's why i updated the code. 7 | Now you are up-to-date with the latest releases, enjoy 8 | -------------------------------------------------------------------------------- /pic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenwaldek/pythonprogramming/96ccadea7cc6bce1dbd1ed8b7973ebc0a7f770d2/pic.png -------------------------------------------------------------------------------- /pyqt5_lesson_01.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 1 Version: 1.0 7 | # Date: 08-01-17 Language: python3 8 | # Description: pyqt5 simple example of empty window 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | 12 | # do something 13 | import sys 14 | from PyQt5.QtWidgets import QApplication, QWidget 15 | 16 | app = QApplication(sys.argv) 17 | 18 | window = QWidget() 19 | window.setGeometry(50, 50, 500, 300) 20 | window.setWindowTitle('pyQt Tuts') 21 | 22 | window.show() 23 | sys.exit(app.exec_()) 24 | -------------------------------------------------------------------------------- /pyqt5_lesson_02.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 2 Version: 1.0 7 | # Date: 08-01-17 Language: python3 8 | # Description: pyqt5 gui empty window with title 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | 12 | # do something 13 | import sys 14 | from PyQt5.QtGui import QIcon 15 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow 16 | 17 | class window(QMainWindow): 18 | 19 | def __init__(self): 20 | super(window, self).__init__() 21 | self.setGeometry(50, 50, 500, 300) 22 | self.setWindowTitle('pyqt5 Tut') 23 | # self.setWindowIcon(QIcon('pic.png')) 24 | self.show() 25 | 26 | app = QApplication(sys.argv) 27 | Gui = window() 28 | sys.exit(app.exec_()) 29 | -------------------------------------------------------------------------------- /pyqt5_lesson_03.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 3 Version: 1.0 7 | # Date: 08-01-17 Language: python3 8 | # Description: pyqt5 gui add pushButton 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | 12 | # do something 13 | import sys 14 | from PyQt5.QtCore import QCoreApplication 15 | from PyQt5.QtGui import * 16 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton 17 | 18 | 19 | class window(QMainWindow): 20 | 21 | def __init__(self): 22 | super(window, self).__init__() 23 | self.setGeometry(50, 50, 500, 300) 24 | self.setWindowTitle('pyqt5 Tut') 25 | # self.setWindowIcon(QIcon('pic.png')) 26 | self.home() 27 | 28 | def home(self): 29 | btn = QPushButton('quit', self) 30 | btn.clicked.connect(QCoreApplication.instance().quit) 31 | btn.resize(100, 100) 32 | btn.move(100, 100) 33 | self.show() 34 | 35 | def run(): 36 | app = QApplication(sys.argv) 37 | Gui = window() 38 | sys.exit(app.exec_()) 39 | 40 | run() 41 | -------------------------------------------------------------------------------- /pyqt5_lesson_04.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 4 Version: 1.0 7 | # Date: 08-01-17 Language: python3 8 | # Description: pyqt5 gui and button function 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | 12 | # do something 13 | import sys 14 | from PyQt5.QtCore import QCoreApplication 15 | from PyQt5.QtGui import * 16 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton 17 | 18 | 19 | class window(QMainWindow): 20 | 21 | def __init__(self): 22 | super(window, self).__init__() 23 | self.setGeometry(50, 50, 500, 300) 24 | self.setWindowTitle('pyqt5 Tut') 25 | # self.setWindowIcon(QIcon('pic.png')) 26 | self.home() 27 | 28 | def home(self): 29 | btn = QPushButton('quit', self) 30 | btn.clicked.connect(self.close_application) 31 | 32 | btn.resize(btn.sizeHint()) #set to acceptable size automatic 33 | btn.move(0, 0) 34 | self.show() 35 | 36 | def close_application(self): 37 | print('whooo so custom') 38 | sys.exit() 39 | 40 | def run(): 41 | app = QApplication(sys.argv) 42 | Gui = window() 43 | sys.exit(app.exec_()) 44 | 45 | run() 46 | -------------------------------------------------------------------------------- /pyqt5_lesson_05.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 5 Version: 1.0 7 | # Date: 08-01-17 Language: python3 8 | # Description: pyqt5 gui add menubar 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | 12 | # do something 13 | import sys 14 | from PyQt5.QtCore import QCoreApplication 15 | from PyQt5.QtGui import * 16 | from PyQt5.QtGui import QIcon 17 | from PyQt5.QtWidgets import QAction 18 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton 19 | 20 | 21 | class window(QMainWindow): 22 | 23 | def __init__(self): 24 | super(window, self).__init__() 25 | self.setGeometry(50, 50, 500, 300) 26 | self.setWindowTitle('pyqt5 Tut') 27 | # self.setWindowIcon(QIcon('pic.png')) 28 | 29 | extractAction = QAction('&Get to the choppah', self) 30 | extractAction.setShortcut('Ctrl+Q') 31 | extractAction.setStatusTip('leave the app') 32 | extractAction.triggered.connect(self.close_application) 33 | 34 | self.statusBar() 35 | 36 | mainMenu = self.menuBar() 37 | fileMenu = mainMenu.addMenu('&File') 38 | fileMenu.addAction(extractAction) 39 | 40 | self.home() 41 | 42 | def home(self): 43 | btn = QPushButton('quit', self) 44 | btn.clicked.connect(self.close_application) 45 | 46 | btn.resize(btn.sizeHint()) 47 | btn.move(0, 100) 48 | self.show() 49 | 50 | def close_application(self): 51 | print('whooo so custom') 52 | sys.exit() 53 | 54 | def run(): 55 | app = QApplication(sys.argv) 56 | Gui = window() 57 | sys.exit(app.exec_()) 58 | 59 | run() 60 | -------------------------------------------------------------------------------- /pyqt5_lesson_06.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 6 Version: 1.0 7 | # Date: 08-01-17 Language: python3 8 | # Description: pyqt5 gui add toolbar 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | 12 | # do something 13 | import sys 14 | from PyQt5.QtCore import QCoreApplication 15 | # from PyQt5.QtGui import * 16 | from PyQt5.QtGui import QIcon 17 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QAction 18 | from PyQt5.uic.properties import QtGui 19 | 20 | 21 | class window(QMainWindow): 22 | 23 | def __init__(self): 24 | super(window, self).__init__() 25 | self.setGeometry(50, 50, 500, 300) 26 | self.setWindowTitle('pyqt5 Tut') 27 | # self.setWindowIcon(QIcon('pic.png')) 28 | 29 | extractAction = QAction('&Get to the choppah', self) 30 | extractAction.setShortcut('Ctrl+Q') 31 | extractAction.setStatusTip('leave the app') 32 | extractAction.triggered.connect(self.close_application) 33 | 34 | self.statusBar() 35 | 36 | mainMenu = self.menuBar() 37 | fileMenu = mainMenu.addMenu('&File') 38 | fileMenu.addAction(extractAction) 39 | 40 | extractAction = QAction(QIcon('pic.png'), 'flee the scene', self) 41 | extractAction.triggered.connect(self.close_application) 42 | 43 | self.toolBar = self.addToolBar('Extraction') 44 | self.toolBar.addAction(extractAction) 45 | 46 | self.home() 47 | 48 | def home(self): 49 | btn = QPushButton('quit', self) 50 | btn.clicked.connect(self.close_application) 51 | btn.resize(btn.sizeHint()) 52 | btn.move(0, 100) 53 | 54 | self.show() 55 | 56 | def close_application(self): 57 | print('whooo so custom') 58 | sys.exit() 59 | 60 | if __name__ == "__main__": 61 | def run(): 62 | app = QApplication(sys.argv) 63 | Gui = window() 64 | sys.exit(app.exec_()) 65 | 66 | run() 67 | -------------------------------------------------------------------------------- /pyqt5_lesson_07.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 7 Version: 1.0 7 | # Date: 08-01-17 Language: python3 8 | # Description: pyqt5 gui messageBox quit application 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | 12 | # do something 13 | import sys 14 | from PyQt5.QtCore import QCoreApplication 15 | # from PyQt5.QtGui import * 16 | from PyQt5.QtGui import QIcon 17 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QAction, QMessageBox 18 | from PyQt5.uic.properties import QtGui 19 | 20 | 21 | class window(QMainWindow): 22 | 23 | def __init__(self): 24 | super(window, self).__init__() 25 | self.setGeometry(50, 50, 500, 300) 26 | self.setWindowTitle('pyqt5 Tut') 27 | # self.setWindowIcon(QIcon('pic.png')) 28 | 29 | extractAction = QAction('&Get to the choppah', self) 30 | extractAction.setShortcut('Ctrl+Q') 31 | extractAction.setStatusTip('leave the app') 32 | extractAction.triggered.connect(self.close_application) 33 | 34 | self.statusBar() 35 | 36 | mainMenu = self.menuBar() 37 | fileMenu = mainMenu.addMenu('&File') 38 | fileMenu.addAction(extractAction) 39 | 40 | extractAction = QAction(QIcon('pic.png'), 'flee the scene', self) 41 | extractAction.triggered.connect(self.close_application) 42 | 43 | self.toolBar = self.addToolBar('extraction') 44 | self.toolBar.addAction(extractAction) 45 | 46 | self.home() 47 | 48 | def home(self): 49 | btn = QPushButton('quit', self) 50 | btn.clicked.connect(self.close_application) 51 | btn.resize(btn.sizeHint()) 52 | btn.move(0, 100) 53 | 54 | self.show() 55 | 56 | def close_application(self): 57 | 58 | choice = QMessageBox.question(self, 'Message', 59 | "Are you sure to quit?", QMessageBox.Yes | 60 | QMessageBox.No, QMessageBox.No) 61 | 62 | if choice == QMessageBox.Yes: 63 | print('quit application') 64 | sys.exit() 65 | else: 66 | pass 67 | 68 | if __name__ == "__main__": # had to add this otherwise app crashed 69 | 70 | def run(): 71 | app = QApplication(sys.argv) 72 | Gui = window() 73 | sys.exit(app.exec_()) 74 | 75 | run() 76 | -------------------------------------------------------------------------------- /pyqt5_lesson_08.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 8 Version: 1.0 7 | # Date: 08-01-17 Language: python3 8 | # Description: pyqt5 gui messageBox quit application 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | 12 | # do something 13 | import sys 14 | from PyQt5.QtCore import QCoreApplication, Qt 15 | from PyQt5.QtGui import QIcon 16 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QAction, QMessageBox 17 | from PyQt5.QtWidgets import QCheckBox 18 | 19 | 20 | 21 | class window(QMainWindow): 22 | 23 | def __init__(self): 24 | super(window, self).__init__() 25 | self.setGeometry(50, 50, 500, 300) 26 | self.setWindowTitle('pyqt5 Tut') 27 | # self.setWindowIcon(QIcon('pic.png')) 28 | 29 | extractAction = QAction('&Get to the choppah', self) 30 | extractAction.setShortcut('Ctrl+Q') 31 | extractAction.setStatusTip('leave the app') 32 | extractAction.triggered.connect(self.close_application) 33 | 34 | self.statusBar() 35 | 36 | mainMenu = self.menuBar() 37 | fileMenu = mainMenu.addMenu('&File') 38 | fileMenu.addAction(extractAction) 39 | 40 | extractAction = QAction(QIcon('pic.png'), 'flee the scene', self) 41 | extractAction.triggered.connect(self.close_application) 42 | 43 | self.toolBar = self.addToolBar('extraction') 44 | self.toolBar.addAction(extractAction) 45 | 46 | self.home() 47 | 48 | def home(self): 49 | btn = QPushButton('quit', self) 50 | btn.clicked.connect(self.close_application) 51 | btn.resize(btn.sizeHint()) 52 | btn.move(0, 100) 53 | 54 | checkBox = QCheckBox('Enlarge window', self) 55 | # checkBox.toggle() # if you want to be checked in in the begin 56 | checkBox.move(0, 50) 57 | checkBox.stateChanged.connect(self.enlarge_window) 58 | 59 | 60 | self.show() 61 | 62 | def enlarge_window(self, state): 63 | if state == Qt.Checked: 64 | self.setGeometry(50, 50, 1000, 600) 65 | else: 66 | self.setGeometry(50, 50 , 500, 300) 67 | 68 | 69 | def close_application(self): 70 | 71 | choice = QMessageBox.question(self, 'Message', 72 | "Are you sure to quit?", QMessageBox.Yes | 73 | QMessageBox.No, QMessageBox.No) 74 | 75 | if choice == QMessageBox.Yes: 76 | print('quit application') 77 | sys.exit() 78 | else: 79 | pass 80 | 81 | 82 | if __name__ == "__main__": # had to add this otherwise app crashed 83 | 84 | def run(): 85 | app = QApplication(sys.argv) 86 | Gui = window() 87 | sys.exit(app.exec_()) 88 | 89 | run() 90 | -------------------------------------------------------------------------------- /pyqt5_lesson_09.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 9 Version: 1.0 7 | # Date: 08-01-17 Language: python3 8 | # Description: pyqt5 gui and progressBar 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | 12 | # do something 13 | import sys 14 | from PyQt5.QtCore import QCoreApplication, Qt 15 | from PyQt5.QtGui import QIcon 16 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QAction, QMessageBox 17 | from PyQt5.QtWidgets import QCheckBox, QProgressBar 18 | 19 | class window(QMainWindow): 20 | 21 | def __init__(self): 22 | super(window, self).__init__() 23 | self.setGeometry(50, 50, 500, 300) 24 | self.setWindowTitle('pyqt5 Tut') 25 | # self.setWindowIcon(QIcon('pic.png')) 26 | 27 | extractAction = QAction('&Get to the choppah', self) 28 | extractAction.setShortcut('Ctrl+Q') 29 | extractAction.setStatusTip('leave the app') 30 | extractAction.triggered.connect(self.close_application) 31 | 32 | self.statusBar() 33 | 34 | mainMenu = self.menuBar() 35 | fileMenu = mainMenu.addMenu('&File') 36 | fileMenu.addAction(extractAction) 37 | 38 | extractAction = QAction(QIcon('pic.png'), 'flee the scene', self) 39 | extractAction.triggered.connect(self.close_application) 40 | 41 | self.toolBar = self.addToolBar('extraction') 42 | self.toolBar.addAction(extractAction) 43 | 44 | self.home() 45 | 46 | def home(self): 47 | btn = QPushButton('quit', self) 48 | btn.clicked.connect(self.close_application) 49 | btn.resize(btn.sizeHint()) 50 | btn.move(0, 100) 51 | 52 | checkBox = QCheckBox('Enlarge window', self) 53 | # checkBox.toggle() # if you want to be checked in in the begin 54 | checkBox.move(0, 50) 55 | checkBox.stateChanged.connect(self.enlarge_window) 56 | 57 | self.progress = QProgressBar(self) 58 | self.progress.setGeometry(200, 80, 250, 20) 59 | 60 | self.btn = QPushButton('download', self) 61 | self.btn.move(200, 120) 62 | self.btn.clicked.connect(self.download) 63 | 64 | 65 | self.show() 66 | 67 | def download(self): 68 | self.completed = 0 69 | 70 | while self.completed < 100: 71 | self.completed += 0.0001 72 | self.progress.setValue(self.completed) 73 | 74 | 75 | 76 | def enlarge_window(self, state): 77 | if state == Qt.Checked: 78 | self.setGeometry(50, 50, 1000, 600) 79 | else: 80 | self.setGeometry(50, 50 , 500, 300) 81 | 82 | 83 | def close_application(self): 84 | 85 | choice = QMessageBox.question(self, 'Message', 86 | "Are you sure to quit?", QMessageBox.Yes | 87 | QMessageBox.No, QMessageBox.No) 88 | 89 | if choice == QMessageBox.Yes: 90 | print('quit application') 91 | sys.exit() 92 | else: 93 | pass 94 | 95 | 96 | if __name__ == "__main__": # had to add this otherwise app crashed 97 | 98 | def run(): 99 | app = QApplication(sys.argv) 100 | Gui = window() 101 | sys.exit(app.exec_()) 102 | 103 | run() 104 | -------------------------------------------------------------------------------- /pyqt5_lesson_10.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 10 Version: 1.0 7 | # Date: 08-01-17 Language: python3 8 | # Description: pyqt5 gui and dropdown menu 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | # do something 12 | import sys 13 | from PyQt5.QtCore import QCoreApplication, Qt 14 | from PyQt5.QtGui import QIcon 15 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QAction, QMessageBox 16 | from PyQt5.QtWidgets import QCheckBox, QProgressBar, QComboBox, QLabel, QStyleFactory 17 | 18 | 19 | 20 | class window(QMainWindow): 21 | 22 | def __init__(self): 23 | super(window, self).__init__() 24 | self.setGeometry(50, 50, 500, 300) 25 | self.setWindowTitle('pyqt5 Tut') 26 | # self.setWindowIcon(QIcon('pic.png')) 27 | 28 | extractAction = QAction('&Get to the choppah', self) 29 | extractAction.setShortcut('Ctrl+Q') 30 | extractAction.setStatusTip('leave the app') 31 | extractAction.triggered.connect(self.close_application) 32 | 33 | self.statusBar() 34 | 35 | mainMenu = self.menuBar() 36 | fileMenu = mainMenu.addMenu('&File') 37 | fileMenu.addAction(extractAction) 38 | 39 | extractAction = QAction(QIcon('pic.png'), 'flee the scene', self) 40 | extractAction.triggered.connect(self.close_application) 41 | 42 | self.toolBar = self.addToolBar('extraction') 43 | self.toolBar.addAction(extractAction) 44 | 45 | self.home() 46 | 47 | def home(self): 48 | btn = QPushButton('quit', self) 49 | btn.clicked.connect(self.close_application) 50 | btn.resize(btn.sizeHint()) 51 | btn.move(0, 25) 52 | 53 | checkBox = QCheckBox('Enlarge window', self) 54 | # checkBox.toggle() # if you want to be checked in in the begin 55 | checkBox.move(0, 50) 56 | checkBox.stateChanged.connect(self.enlarge_window) 57 | 58 | self.progress = QProgressBar(self) 59 | self.progress.setGeometry(200, 80, 250, 20) 60 | 61 | self.btn = QPushButton('download', self) 62 | self.btn.move(200, 120) 63 | self.btn.clicked.connect(self.download) 64 | 65 | self.styleChoise = QLabel('Windows', self) 66 | comboBox = QComboBox(self) 67 | comboBox.addItem('motif') 68 | comboBox.addItem('Windows') 69 | comboBox.addItem('cde') 70 | comboBox.addItem('Plastique') 71 | comboBox.addItem('Cleanlooks') 72 | comboBox.addItem('windowsvista') 73 | 74 | comboBox.move(25, 250) 75 | self.styleChoise.move(25, 150) 76 | comboBox.activated[str].connect(self.style_choise) 77 | 78 | self.show() 79 | 80 | def style_choise(self, text): 81 | self.styleChoise.setText(text) 82 | QApplication.setStyle(QStyleFactory.create(text)) 83 | 84 | def download(self): 85 | self.completed = 0 86 | 87 | while self.completed < 100: 88 | self.completed += 0.0001 89 | self.progress.setValue(self.completed) 90 | 91 | 92 | def enlarge_window(self, state): 93 | if state == Qt.Checked: 94 | self.setGeometry(50, 50, 1000, 600) 95 | else: 96 | self.setGeometry(50, 50 , 500, 300) 97 | 98 | 99 | def close_application(self): 100 | 101 | choice = QMessageBox.question(self, 'Message', 102 | "Are you sure to quit?", QMessageBox.Yes | 103 | QMessageBox.No, QMessageBox.No) 104 | 105 | if choice == QMessageBox.Yes: 106 | print('quit application') 107 | sys.exit() 108 | else: 109 | pass 110 | 111 | 112 | if __name__ == "__main__": # had to add this otherwise app crashed 113 | 114 | def run(): 115 | app = QApplication(sys.argv) 116 | Gui = window() 117 | sys.exit(app.exec_()) 118 | 119 | run() 120 | -------------------------------------------------------------------------------- /pyqt5_lesson_11.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 11 Version: 1.0 7 | # Date: 09-01-17 Language: python3 8 | # Description: pyqt5 gui and font widget 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | # do something 12 | import sys 13 | from PyQt5.QtCore import QCoreApplication, Qt 14 | from PyQt5.QtGui import QIcon 15 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QAction, QMessageBox 16 | from PyQt5.QtWidgets import QCheckBox, QProgressBar, QComboBox, QLabel, QStyleFactory 17 | from PyQt5.QtWidgets import QFontDialog 18 | 19 | 20 | class window(QMainWindow): 21 | 22 | def __init__(self): 23 | super(window, self).__init__() 24 | self.setGeometry(50, 50, 500, 300) 25 | self.setWindowTitle('pyqt5 Tut') 26 | # self.setWindowIcon(QIcon('pic.png')) 27 | 28 | extractAction = QAction('&Get to the choppah', self) 29 | extractAction.setShortcut('Ctrl+Q') 30 | extractAction.setStatusTip('leave the app') 31 | extractAction.triggered.connect(self.close_application) 32 | 33 | self.statusBar() 34 | 35 | mainMenu = self.menuBar() 36 | fileMenu = mainMenu.addMenu('&File') 37 | fileMenu.addAction(extractAction) 38 | 39 | extractAction = QAction(QIcon('pic.png'), 'flee the scene', self) 40 | extractAction.triggered.connect(self.close_application) 41 | self.toolBar = self.addToolBar('extraction') 42 | self.toolBar.addAction(extractAction) 43 | 44 | fontChoice = QAction('Font', self) 45 | fontChoice.triggered.connect(self.font_choice) 46 | # self.toolBar = self.addToolBar('Font') 47 | self.toolBar.addAction(fontChoice) 48 | 49 | self.home() 50 | 51 | def font_choice(self): 52 | font, valid = QFontDialog.getFont() 53 | if valid: 54 | self.styleChoice.setFont(font) 55 | 56 | def home(self): 57 | btn = QPushButton('quit', self) 58 | btn.clicked.connect(self.close_application) 59 | btn.resize(btn.sizeHint()) 60 | btn.move(0, 100) 61 | 62 | checkBox = QCheckBox('Enlarge window', self) 63 | # checkBox.toggle() # if you want to be checked in in the begin 64 | checkBox.move(0, 50) 65 | checkBox.stateChanged.connect(self.enlarge_window) 66 | 67 | self.progress = QProgressBar(self) 68 | self.progress.setGeometry(200, 80, 250, 20) 69 | 70 | self.btn = QPushButton('download', self) 71 | self.btn.move(200, 120) 72 | self.btn.clicked.connect(self.download) 73 | 74 | self.styleChoice = QLabel('Windows', self) 75 | comboBox = QComboBox(self) 76 | comboBox.addItem('motif') 77 | comboBox.addItem('Windows') 78 | comboBox.addItem('cde') 79 | comboBox.addItem('Plastique') 80 | comboBox.addItem('Cleanlooks') 81 | comboBox.addItem('windowsvista') 82 | 83 | comboBox.move(25, 250) 84 | self.styleChoice.move(25, 150) 85 | comboBox.activated[str].connect(self.style_choice) 86 | 87 | self.show() 88 | 89 | 90 | def style_choice(self, text): 91 | self.styleChoice.setText(text) 92 | QApplication.setStyle(QStyleFactory.create(text)) 93 | 94 | def download(self): 95 | self.completed = 0 96 | 97 | while self.completed < 100: 98 | self.completed += 0.0001 99 | self.progress.setValue(self.completed) 100 | 101 | 102 | def enlarge_window(self, state): 103 | if state == Qt.Checked: 104 | self.setGeometry(50, 50, 1000, 600) 105 | else: 106 | self.setGeometry(50, 50 , 500, 300) 107 | 108 | 109 | def close_application(self): 110 | 111 | choice = QMessageBox.question(self, 'Message', 112 | "Are you sure to quit?", QMessageBox.Yes | 113 | QMessageBox.No, QMessageBox.No) 114 | 115 | if choice == QMessageBox.Yes: 116 | print('quit application') 117 | sys.exit() 118 | else: 119 | pass 120 | 121 | 122 | if __name__ == "__main__": # had to add this otherwise app crashed 123 | 124 | def run(): 125 | app = QApplication(sys.argv) 126 | Gui = window() 127 | sys.exit(app.exec_()) 128 | 129 | run() 130 | -------------------------------------------------------------------------------- /pyqt5_lesson_12.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 12 Version: 1.0 7 | # Date: 09-01-17 Language: python3 8 | # Description: pyqt5 gui and color picker widget 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | # do something 12 | import sys 13 | from PyQt5.QtCore import QCoreApplication, Qt 14 | from PyQt5.QtGui import QIcon, QColor 15 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QAction, QMessageBox 16 | from PyQt5.QtWidgets import QCalendarWidget, QFontDialog 17 | from PyQt5.QtWidgets import QCheckBox, QProgressBar, QComboBox, QLabel, QStyleFactory 18 | from PyQt5.QtWidgets import QColorDialog 19 | 20 | 21 | class window(QMainWindow): 22 | 23 | def __init__(self): 24 | super(window, self).__init__() 25 | self.setGeometry(50, 50, 800, 500) 26 | self.setWindowTitle('pyqt5 Tut') 27 | # self.setWindowIcon(QIcon('pic.png')) 28 | 29 | extractAction = QAction('&Get to the choppah', self) 30 | extractAction.setShortcut('Ctrl+Q') 31 | extractAction.setStatusTip('leave the app') 32 | extractAction.triggered.connect(self.close_application) 33 | 34 | self.statusBar() 35 | 36 | mainMenu = self.menuBar() 37 | fileMenu = mainMenu.addMenu('&File') 38 | fileMenu.addAction(extractAction) 39 | 40 | extractAction = QAction(QIcon('pic.png'), 'flee the scene', self) 41 | extractAction.triggered.connect(self.close_application) 42 | self.toolBar = self.addToolBar('extraction') 43 | self.toolBar.addAction(extractAction) 44 | 45 | fontChoice = QAction('Font', self) 46 | fontChoice.triggered.connect(self.font_choice) 47 | # self.toolBar = self.addToolBar('Font') 48 | self.toolBar.addAction(fontChoice) 49 | 50 | cal = QCalendarWidget(self) 51 | cal.move(500, 200) 52 | cal.resize(200, 200) 53 | 54 | self.home() 55 | 56 | def color_picker(self): 57 | color = QColorDialog.getColor() 58 | self.styleChoice.setStyleSheet('QWidget{background-color: %s}' % color.name()) 59 | 60 | def font_choice(self): 61 | font, valid = QFontDialog.getFont() 62 | if valid: 63 | self.styleChoice.setFont(font) 64 | 65 | def home(self): 66 | btn = QPushButton('quit', self) 67 | btn.clicked.connect(self.close_application) 68 | btn.resize(btn.sizeHint()) 69 | btn.move(0, 100) 70 | 71 | checkBox = QCheckBox('Enlarge window', self) 72 | # checkBox.toggle() # if you want to be checked in in the begin 73 | checkBox.move(0, 50) 74 | checkBox.stateChanged.connect(self.enlarge_window) 75 | 76 | self.progress = QProgressBar(self) 77 | self.progress.setGeometry(200, 80, 250, 20) 78 | 79 | self.btn = QPushButton('download', self) 80 | self.btn.move(200, 120) 81 | self.btn.clicked.connect(self.download) 82 | 83 | self.styleChoice = QLabel('Windows', self) 84 | comboBox = QComboBox(self) 85 | comboBox.addItem('motif') 86 | comboBox.addItem('Windows') 87 | comboBox.addItem('cde') 88 | comboBox.addItem('Plastique') 89 | comboBox.addItem('Cleanlooks') 90 | comboBox.addItem('windowsvista') 91 | 92 | comboBox.move(25, 250) 93 | self.styleChoice.move(25, 150) 94 | comboBox.activated[str].connect(self.style_choice) 95 | 96 | color = QColor(0,0,0) 97 | fontColer = QAction('font bg color', self) 98 | fontColer.triggered.connect(self.color_picker) 99 | self.toolBar.addAction(fontColer) 100 | 101 | self.show() 102 | 103 | 104 | 105 | def style_choice(self, text): 106 | self.styleChoice.setText(text) 107 | QApplication.setStyle(QStyleFactory.create(text)) 108 | 109 | def download(self): 110 | self.completed = 0 111 | 112 | while self.completed < 100: 113 | self.completed += 0.0001 114 | self.progress.setValue(self.completed) 115 | 116 | 117 | def enlarge_window(self, state): 118 | if state == Qt.Checked: 119 | self.setGeometry(50, 50, 1000, 600) 120 | else: 121 | self.setGeometry(50, 50 , 500, 300) 122 | 123 | 124 | def close_application(self): 125 | 126 | choice = QMessageBox.question(self, 'Message', 127 | "Are you sure to quit?", QMessageBox.Yes | 128 | QMessageBox.No, QMessageBox.No) 129 | 130 | if choice == QMessageBox.Yes: 131 | print('quit application') 132 | sys.exit() 133 | else: 134 | pass 135 | 136 | 137 | if __name__ == "__main__": # had to add this otherwise app crashed 138 | 139 | def run(): 140 | app = QApplication(sys.argv) 141 | Gui = window() 142 | sys.exit(app.exec_()) 143 | 144 | run() 145 | -------------------------------------------------------------------------------- /pyqt5_lesson_13.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 13 Version: 1.0 7 | # Date: 09-01-17 Language: python3 8 | # Description: pyqt5 gui and editor 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | # do something 12 | import sys 13 | from PyQt5.QtCore import QCoreApplication, Qt 14 | from PyQt5.QtGui import QIcon, QColor 15 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QAction, QMessageBox 16 | from PyQt5.QtWidgets import QCalendarWidget, QFontDialog 17 | from PyQt5.QtWidgets import QCheckBox, QProgressBar, QComboBox, QLabel, QStyleFactory 18 | from PyQt5.QtWidgets import QColorDialog, QTextEdit 19 | 20 | 21 | class window(QMainWindow): 22 | 23 | def __init__(self): 24 | super(window, self).__init__() 25 | self.setGeometry(50, 50, 800, 500) 26 | self.setWindowTitle('pyqt5 Tut') 27 | # self.setWindowIcon(QIcon('pic.png')) 28 | 29 | extractAction = QAction('&Get to the choppah', self) 30 | extractAction.setShortcut('Ctrl+Q') 31 | extractAction.setStatusTip('leave the app') 32 | extractAction.triggered.connect(self.close_application) 33 | 34 | openEditor = QAction('&Editor', self) 35 | openEditor.setShortcut('Ctrl+E') 36 | openEditor.setStatusTip('Open Editor') 37 | openEditor.triggered.connect(self.editor) 38 | 39 | self.statusBar() 40 | 41 | mainMenu = self.menuBar() 42 | fileMenu = mainMenu.addMenu('&File') 43 | fileMenu.addAction(extractAction) 44 | 45 | editorMenu = mainMenu.addMenu('&Editor') 46 | editorMenu.addAction(openEditor) 47 | 48 | extractAction = QAction(QIcon('pic.png'), 'flee the scene', self) 49 | extractAction.triggered.connect(self.close_application) 50 | self.toolBar = self.addToolBar('extraction') 51 | self.toolBar.addAction(extractAction) 52 | 53 | fontChoice = QAction('Font', self) 54 | fontChoice.triggered.connect(self.font_choice) 55 | # self.toolBar = self.addToolBar('Font') 56 | self.toolBar.addAction(fontChoice) 57 | 58 | cal = QCalendarWidget(self) 59 | cal.move(500, 200) 60 | cal.resize(200, 200) 61 | 62 | self.home() 63 | 64 | def editor(self): 65 | self.textEdit = QTextEdit() 66 | self.setCentralWidget(self.textEdit) 67 | 68 | def color_picker(self): 69 | color = QColorDialog.getColor() 70 | self.styleChoice.setStyleSheet('QWidget{background-color: %s}' % color.name()) 71 | 72 | def font_choice(self): 73 | font, valid = QFontDialog.getFont() 74 | if valid: 75 | self.styleChoice.setFont(font) 76 | 77 | def home(self): 78 | btn = QPushButton('quit', self) 79 | btn.clicked.connect(self.close_application) 80 | btn.resize(btn.sizeHint()) 81 | btn.move(0, 100) 82 | 83 | checkBox = QCheckBox('Enlarge window', self) 84 | # checkBox.toggle() # if you want to be checked in in the begin 85 | checkBox.move(0, 50) 86 | checkBox.stateChanged.connect(self.enlarge_window) 87 | 88 | self.progress = QProgressBar(self) 89 | self.progress.setGeometry(200, 80, 250, 20) 90 | 91 | self.btn = QPushButton('download', self) 92 | self.btn.move(200, 120) 93 | self.btn.clicked.connect(self.download) 94 | 95 | self.styleChoice = QLabel('Windows', self) 96 | comboBox = QComboBox(self) 97 | comboBox.addItem('motif') 98 | comboBox.addItem('Windows') 99 | comboBox.addItem('cde') 100 | comboBox.addItem('Plastique') 101 | comboBox.addItem('Cleanlooks') 102 | comboBox.addItem('windowsvista') 103 | 104 | comboBox.move(25, 250) 105 | self.styleChoice.move(25, 150) 106 | comboBox.activated[str].connect(self.style_choice) 107 | 108 | color = QColor(0,0,0) 109 | fontColer = QAction('font bg color', self) 110 | fontColer.triggered.connect(self.color_picker) 111 | self.toolBar.addAction(fontColer) 112 | 113 | self.show() 114 | 115 | def style_choice(self, text): 116 | self.styleChoice.setText(text) 117 | QApplication.setStyle(QStyleFactory.create(text)) 118 | 119 | def download(self): 120 | self.completed = 0 121 | 122 | while self.completed < 100: 123 | self.completed += 0.0001 124 | self.progress.setValue(self.completed) 125 | 126 | 127 | def enlarge_window(self, state): 128 | if state == Qt.Checked: 129 | self.setGeometry(50, 50, 1000, 600) 130 | else: 131 | self.setGeometry(50, 50 , 500, 300) 132 | 133 | 134 | def close_application(self): 135 | 136 | choice = QMessageBox.question(self, 'Message', 137 | "Are you sure to quit?", QMessageBox.Yes | 138 | QMessageBox.No, QMessageBox.No) 139 | 140 | if choice == QMessageBox.Yes: 141 | print('quit application') 142 | sys.exit() 143 | else: 144 | pass 145 | 146 | 147 | if __name__ == "__main__": # had to add this otherwise app crashed 148 | 149 | def run(): 150 | app = QApplication(sys.argv) 151 | Gui = window() 152 | sys.exit(app.exec_()) 153 | 154 | run() 155 | -------------------------------------------------------------------------------- /pyqt5_lesson_14.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 14 Version: 1.0 7 | # Date: 09-01-17 Language: python3 8 | # Description: pyqt5 gui and opening files 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | # do something 12 | 13 | 14 | import sys 15 | from PyQt5.QtCore import QCoreApplication, Qt 16 | from PyQt5.QtGui import QIcon, QColor 17 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QAction, QMessageBox 18 | from PyQt5.QtWidgets import QCalendarWidget, QFontDialog, QColorDialog, QTextEdit, QFileDialog 19 | from PyQt5.QtWidgets import QCheckBox, QProgressBar, QComboBox, QLabel, QStyleFactory, QLineEdit, QInputDialog 20 | 21 | 22 | 23 | class window(QMainWindow): 24 | 25 | def __init__(self): 26 | super(window, self).__init__() 27 | self.setGeometry(50, 50, 800, 500) 28 | self.setWindowTitle('pyqt5 Tut') 29 | self.setWindowIcon(QIcon('pic.png')) 30 | 31 | extractAction = QAction('&Get to the choppah', self) 32 | extractAction.setShortcut('Ctrl+Q') 33 | extractAction.setStatusTip('leave the app') 34 | extractAction.triggered.connect(self.close_application) 35 | 36 | openEditor = QAction('&Editor', self) 37 | openEditor.setShortcut('Ctrl+E') 38 | openEditor.setStatusTip('Open Editor') 39 | openEditor.triggered.connect(self.editor) 40 | 41 | openFile = QAction('&Open File', self) 42 | openFile.setShortcut('Ctrl+O') 43 | openFile.setStatusTip('Open File') 44 | openFile.triggered.connect(self.file_open) 45 | 46 | self.statusBar() 47 | 48 | mainMenu = self.menuBar() 49 | fileMenu = mainMenu.addMenu('&File') 50 | fileMenu.addAction(extractAction) 51 | 52 | fileMenu.addAction(openFile) 53 | 54 | editorMenu = mainMenu.addMenu('&Editor') 55 | editorMenu.addAction(openEditor) 56 | 57 | extractAction = QAction(QIcon('pic.png'), 'flee the scene', self) 58 | extractAction.triggered.connect(self.close_application) 59 | self.toolBar = self.addToolBar('extraction') 60 | self.toolBar.addAction(extractAction) 61 | 62 | fontChoice = QAction('Font', self) 63 | fontChoice.triggered.connect(self.font_choice) 64 | # self.toolBar = self.addToolBar('Font') 65 | self.toolBar.addAction(fontChoice) 66 | 67 | cal = QCalendarWidget(self) 68 | cal.move(500, 200) 69 | cal.resize(200, 200) 70 | 71 | self.home() 72 | 73 | def editor(self): 74 | self.textEdit = QTextEdit() 75 | self.setCentralWidget(self.textEdit) 76 | 77 | 78 | 79 | def file_open(self): 80 | # need to make name an tupple otherwise i had an error and app crashed 81 | name, _ = QFileDialog.getOpenFileName(self, 'Open File', options=QFileDialog.DontUseNativeDialog) 82 | print('tot na dialog gelukt') 83 | file = open(name, 'r') 84 | print('na het inlezen gelukt') 85 | self.editor() 86 | 87 | with file: 88 | text = file.read() 89 | self.textEdit.setText(text) 90 | 91 | ##End of code problem 92 | 93 | def color_picker(self): 94 | color = QColorDialog.getColor() 95 | self.styleChoice.setStyleSheet('QWidget{background-color: %s}' % color.name()) 96 | 97 | def font_choice(self): 98 | font, valid = QFontDialog.getFont() 99 | if valid: 100 | self.styleChoice.setFont(font) 101 | 102 | def home(self): 103 | btn = QPushButton('quit', self) 104 | btn.clicked.connect(self.close_application) 105 | btn.resize(btn.sizeHint()) 106 | btn.move(0, 100) 107 | 108 | checkBox = QCheckBox('Enlarge window', self) 109 | # checkBox.toggle() # if you want to be checked in in the begin 110 | checkBox.move(0, 50) 111 | checkBox.stateChanged.connect(self.enlarge_window) 112 | 113 | self.progress = QProgressBar(self) 114 | self.progress.setGeometry(200, 80, 250, 20) 115 | 116 | self.btn = QPushButton('download', self) 117 | self.btn.move(200, 120) 118 | self.btn.clicked.connect(self.download) 119 | 120 | self.styleChoice = QLabel('Windows', self) 121 | comboBox = QComboBox(self) 122 | comboBox.addItem('motif') 123 | comboBox.addItem('Windows') 124 | comboBox.addItem('cde') 125 | comboBox.addItem('Plastique') 126 | comboBox.addItem('Cleanlooks') 127 | comboBox.addItem('windowsvista') 128 | 129 | comboBox.move(25, 250) 130 | self.styleChoice.move(25, 150) 131 | comboBox.activated[str].connect(self.style_choice) 132 | 133 | color = QColor(0,0,0) 134 | fontColer = QAction('font bg color', self) 135 | fontColer.triggered.connect(self.color_picker) 136 | self.toolBar.addAction(fontColer) 137 | 138 | self.show() 139 | 140 | def style_choice(self, text): 141 | self.styleChoice.setText(text) 142 | QApplication.setStyle(QStyleFactory.create(text)) 143 | 144 | def download(self): 145 | self.completed = 0 146 | 147 | while self.completed < 100: 148 | self.completed += 0.0001 149 | self.progress.setValue(self.completed) 150 | 151 | 152 | def enlarge_window(self, state): 153 | if state == Qt.Checked: 154 | self.setGeometry(50, 50, 1000, 600) 155 | else: 156 | self.setGeometry(50, 50 , 500, 300) 157 | 158 | 159 | def close_application(self): 160 | 161 | choice = QMessageBox.question(self, 'Message', 162 | "Are you sure to quit?", QMessageBox.Yes | 163 | QMessageBox.No, QMessageBox.No) 164 | 165 | if choice == QMessageBox.Yes: 166 | print('quit application') 167 | sys.exit() 168 | else: 169 | pass 170 | 171 | 172 | if __name__ == "__main__": # had to add this otherwise app crashed 173 | 174 | def run(): 175 | app = QApplication(sys.argv) 176 | Gui = window() 177 | sys.exit(app.exec_()) 178 | 179 | run() 180 | -------------------------------------------------------------------------------- /pyqt5_lesson_15.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | ############################################################### 4 | # kenwaldek MIT-license 5 | 6 | # Title: PyQt5 lesson 15 Version: 1.0 7 | # Date: 09-01-17 Language: python3 8 | # Description: pyqt5 gui and file saving 9 | # pythonprogramming.net from PyQt4 to PyQt5 10 | ############################################################### 11 | # do something 12 | 13 | 14 | import sys 15 | from PyQt5.QtCore import QCoreApplication, Qt 16 | from PyQt5.QtGui import QIcon, QColor 17 | from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QAction, QMessageBox 18 | from PyQt5.QtWidgets import QCalendarWidget, QFontDialog, QColorDialog, QTextEdit, QFileDialog 19 | from PyQt5.QtWidgets import QCheckBox, QProgressBar, QComboBox, QLabel, QStyleFactory, QLineEdit, QInputDialog 20 | 21 | 22 | 23 | class window(QMainWindow): 24 | 25 | def __init__(self): 26 | super(window, self).__init__() 27 | self.setGeometry(50, 50, 800, 500) 28 | self.setWindowTitle('pyqt5 Tut') 29 | self.setWindowIcon(QIcon('pic.png')) 30 | 31 | extractAction = QAction('&Get to the choppah', self) 32 | extractAction.setShortcut('Ctrl+Q') 33 | extractAction.setStatusTip('leave the app') 34 | extractAction.triggered.connect(self.close_application) 35 | 36 | openEditor = QAction('&Editor', self) 37 | openEditor.setShortcut('Ctrl+E') 38 | openEditor.setStatusTip('Open Editor') 39 | openEditor.triggered.connect(self.editor) 40 | 41 | openFile = QAction('&Open File', self) 42 | openFile.setShortcut('Ctrl+O') 43 | openFile.setStatusTip('Open File') 44 | openFile.triggered.connect(self.file_open) 45 | 46 | saveFile = QAction('&Save File', self) 47 | saveFile.setShortcut('Ctrl+S') 48 | saveFile.setStatusTip('Save File') 49 | saveFile.triggered.connect(self.file_save) 50 | 51 | 52 | self.statusBar() 53 | 54 | mainMenu = self.menuBar() 55 | fileMenu = mainMenu.addMenu('&File') 56 | fileMenu.addAction(extractAction) 57 | 58 | fileMenu.addAction(openFile) 59 | fileMenu.addAction(saveFile) 60 | 61 | 62 | editorMenu = mainMenu.addMenu('&Editor') 63 | editorMenu.addAction(openEditor) 64 | 65 | extractAction = QAction(QIcon('pic.png'), 'flee the scene', self) 66 | extractAction.triggered.connect(self.close_application) 67 | self.toolBar = self.addToolBar('extraction') 68 | self.toolBar.addAction(extractAction) 69 | 70 | fontChoice = QAction('Font', self) 71 | fontChoice.triggered.connect(self.font_choice) 72 | # self.toolBar = self.addToolBar('Font') 73 | self.toolBar.addAction(fontChoice) 74 | 75 | cal = QCalendarWidget(self) 76 | cal.move(500, 200) 77 | cal.resize(200, 200) 78 | 79 | self.home() 80 | 81 | def editor(self): 82 | self.textEdit = QTextEdit() 83 | self.setCentralWidget(self.textEdit) 84 | 85 | def file_open(self): 86 | # need to make name an tupple otherwise i had an error and app crashed 87 | name, _ = QFileDialog.getOpenFileName(self, 'Open File', options=QFileDialog.DontUseNativeDialog) 88 | print('tot na dialog gelukt') # for debugging 89 | file = open(name, 'r') 90 | print('na het inlezen gelukt') # for debugging 91 | self.editor() 92 | 93 | with file: 94 | text = file.read() 95 | self.textEdit.setText(text) 96 | 97 | def file_save(self): 98 | name, _ = QFileDialog.getSaveFileName(self,'Save File', options=QFileDialog.DontUseNativeDialog) 99 | file = open(name, 'w') 100 | text = self.textEdit.toPlainText() 101 | file.write(text) 102 | file.close() 103 | 104 | def color_picker(self): 105 | color = QColorDialog.getColor() 106 | self.styleChoice.setStyleSheet('QWidget{background-color: %s}' % color.name()) 107 | 108 | def font_choice(self): 109 | font, valid = QFontDialog.getFont() 110 | if valid: 111 | self.styleChoice.setFont(font) 112 | 113 | def home(self): 114 | btn = QPushButton('quit', self) 115 | btn.clicked.connect(self.close_application) 116 | btn.resize(btn.sizeHint()) 117 | btn.move(0, 100) 118 | 119 | checkBox = QCheckBox('Enlarge window', self) 120 | # checkBox.toggle() # if you want to be checked in in the begin 121 | checkBox.move(0, 50) 122 | checkBox.stateChanged.connect(self.enlarge_window) 123 | 124 | self.progress = QProgressBar(self) 125 | self.progress.setGeometry(200, 80, 250, 20) 126 | 127 | self.btn = QPushButton('download', self) 128 | self.btn.move(200, 120) 129 | self.btn.clicked.connect(self.download) 130 | 131 | self.styleChoice = QLabel('Windows', self) 132 | comboBox = QComboBox(self) 133 | comboBox.addItem('motif') 134 | comboBox.addItem('Windows') 135 | comboBox.addItem('cde') 136 | comboBox.addItem('Plastique') 137 | comboBox.addItem('Cleanlooks') 138 | comboBox.addItem('windowsvista') 139 | 140 | comboBox.move(25, 250) 141 | self.styleChoice.move(25, 150) 142 | comboBox.activated[str].connect(self.style_choice) 143 | 144 | color = QColor(0,0,0) 145 | fontColer = QAction('font bg color', self) 146 | fontColer.triggered.connect(self.color_picker) 147 | self.toolBar.addAction(fontColer) 148 | 149 | self.show() 150 | 151 | def style_choice(self, text): 152 | self.styleChoice.setText(text) 153 | QApplication.setStyle(QStyleFactory.create(text)) 154 | 155 | def download(self): 156 | self.completed = 0 157 | 158 | while self.completed < 100: 159 | self.completed += 0.0001 160 | self.progress.setValue(self.completed) 161 | 162 | def enlarge_window(self, state): 163 | if state == Qt.Checked: 164 | self.setGeometry(50, 50, 1000, 600) 165 | else: 166 | self.setGeometry(50, 50 , 500, 300) 167 | 168 | def close_application(self): 169 | 170 | choice = QMessageBox.question(self, 'Message', 171 | "Are you sure to quit?", QMessageBox.Yes | 172 | QMessageBox.No, QMessageBox.No) 173 | 174 | if choice == QMessageBox.Yes: 175 | print('quit application') 176 | sys.exit() 177 | else: 178 | pass 179 | 180 | 181 | if __name__ == "__main__": # had to add this otherwise app crashed 182 | 183 | def run(): 184 | app = QApplication(sys.argv) 185 | Gui = window() 186 | sys.exit(app.exec_()) 187 | 188 | run() 189 | --------------------------------------------------------------------------------