Advertisement
Guest User

pyqt5_while_loop

a guest
Oct 26th, 2016
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import sys, time
  2. from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLineEdit, QRadioButton, QPushButton
  3. from PyQt5.QtGui import QIcon, QFont
  4.  
  5. class Widget(QWidget):
  6. def __init__(self, parent=None):
  7. QWidget.__init__(self, parent)
  8.  
  9. self.widget_layout = QVBoxLayout()
  10.  
  11. # Making buttons
  12. self.radio1 = QPushButton('Radio 1')
  13. self.radio2 = QPushButton('Radio 2')
  14.  
  15. # Making the text window
  16. self.line_edit = QLineEdit()
  17. font = self.line_edit.font()
  18. font.setPointSize(32)
  19. self.line_edit.setFont(font)
  20.  
  21. # When the buttons get clicked
  22. self.radio1.clicked.connect(self.radio1_clicked) #[bool] makes it a toggle button?
  23. self.radio2.clicked.connect(self.radio2_clicked)
  24.  
  25. # Place the buttons and line edit onto the screen.
  26. self.widget_layout.addWidget(self.radio1)
  27. self.widget_layout.addWidget(self.radio2)
  28. self.widget_layout.addWidget(self.line_edit)
  29. self.setWindowTitle('While loop test') # Window name
  30. self.setWindowIcon(QIcon('violin.png')) # Icon used by the window.
  31. self.setLayout(self.widget_layout)
  32.  
  33. def radio1_clicked(self):
  34. self.line_edit.setText('Radio 1')
  35.  
  36. def radio2_clicked(self):
  37. self.line_edit.setText('Radio 2')
  38.  
  39. timeout = time.time() + 60*5 # 5 minutes from now
  40.  
  41. if __name__ == '__main__':
  42. app = QApplication(sys.argv)
  43. widget = Widget()
  44. widget.show()
  45. widget.line_edit.setText('Text updated!')
  46.  
  47. while True:
  48. test = 0
  49. if test == 5 or time.time() > timeout:
  50. break
  51. test = test - 1
  52. teststring = str(test)
  53. widget.line_edit.setText(teststring)
  54.  
  55. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement