Advertisement
cmaureir

Untitled

Oct 29th, 2021
1,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. import sys
  2. import time
  3. from PySide6.QtCore import QThread
  4. from PySide6.QtWidgets import (QApplication, QWidget, QPushButton, QComboBox, QVBoxLayout)
  5.  
  6. class Gui(QWidget):
  7.     def __init__(self):
  8.         super().__init__()
  9.         layout = QVBoxLayout()
  10.         button = QPushButton('click me')
  11.         button.clicked.connect(self.do_task)
  12.         combobox = QComboBox()
  13.         combobox.addItems(['1', '2', '3', '4', '5'])
  14.         layout.addWidget(button)
  15.         layout.addWidget(combobox)
  16.         self.setLayout(layout)
  17.  
  18.     def algo(self):
  19.         print('task started')
  20.         k = 0
  21.         for i in range(100):
  22.             for j in range(100):
  23.                 k += 1
  24.                 print(k)
  25.                 time.sleep(0.5)
  26.         print('task finished')
  27.  
  28.     def do_task(self):
  29.         self.thread = QThread()
  30.         self.thread.run = self.algo
  31.         self.thread.start()
  32.  
  33. if __name__ == '__main__':
  34.     app = QApplication(sys.argv)
  35.     window = Gui()
  36.     window.show()
  37.     sys.exit(app.exec())
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement