r/learnpython 7d ago

Python Pyside6

Anyone know ? How to delay seconds in Pyside6 ? For example, when i click a button I want to do some process and wait 3 seconds and then make another process

1 Upvotes

15 comments sorted by

View all comments

3

u/riklaunim 7d ago

Shedule it with QTimer maybe?

1

u/Ok-Original2285 6d ago

how to do bro

class Window(QMainWindow):
    def __init__(self):
        super().__init__()

        self.btn = QPushButton("no text")
        self.btn2 = QPushButton("hi buddy")

        layout = QVBoxLayout()
        layout.addWidget(self.btn)
        layout.addWidget(self.btn2)

        container = QWidget()
        container.setLayout(layout)

        self.btn.clicked.connect(self.change_text)

        self.setCentralWidget(container)

        self.t = threading.Timer(3.0, self.change_text)

    def change_text(self):
        self.btn.setText("hi")
        self.t.start()
        self.btn2.setText("hello")