Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, time
- from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLineEdit, QRadioButton, QPushButton
- from PyQt5.QtGui import QIcon, QFont
- class Widget(QWidget):
- def __init__(self, parent=None):
- QWidget.__init__(self, parent)
- self.widget_layout = QVBoxLayout()
- # Making buttons
- self.radio1 = QPushButton('Radio 1')
- self.radio2 = QPushButton('Radio 2')
- # Making the text window
- self.line_edit = QLineEdit()
- font = self.line_edit.font()
- font.setPointSize(32)
- self.line_edit.setFont(font)
- # When the buttons get clicked
- self.radio1.clicked.connect(self.radio1_clicked) #[bool] makes it a toggle button?
- self.radio2.clicked.connect(self.radio2_clicked)
- # Place the buttons and line edit onto the screen.
- self.widget_layout.addWidget(self.radio1)
- self.widget_layout.addWidget(self.radio2)
- self.widget_layout.addWidget(self.line_edit)
- self.setWindowTitle('While loop test') # Window name
- self.setWindowIcon(QIcon('violin.png')) # Icon used by the window.
- self.setLayout(self.widget_layout)
- def radio1_clicked(self):
- self.line_edit.setText('Radio 1')
- def radio2_clicked(self):
- self.line_edit.setText('Radio 2')
- timeout = time.time() + 60*5 # 5 minutes from now
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- widget = Widget()
- widget.show()
- widget.line_edit.setText('Text updated!')
- while True:
- test = 0
- if test == 5 or time.time() > timeout:
- break
- test = test - 1
- teststring = str(test)
- widget.line_edit.setText(teststring)
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement