PYQT5 Series Tutorials (eight) use of timer Qtimer

Source: Internet
Author: User
Hardware and Software Environment
  • OS X EI Capitan
  • Python 3.5.1
  • PyQt 5.5.1
Objective

If you need to do something periodically in a program, such as detecting the state of a device, a timer is used. This article looks at the use of Qtimer in PyQT5.

Qtimer Example

Suppose you want to implement this function every second, and see how Qtimer is implemented?

self.timer = QTimer(self)self.count = 0self.timer.timeout.connect(self.showNum)self.startCount()

First instantiate a timer and then bind its timeout signal to the custom Shownum () method. Finally call Startcount () This method to start the timer. The above statements are usually placed in the constructor of window or form. The complete example is to write it yourself, and it's very simple.

Startcount () method
def startcount (self):
Self.timer.start (1000)

The Timer.start () time parameter is in milliseconds, note that the Timer timeout () is triggered once per second, and the signal timeout is bound to the slot shownum (). So Shownum () is also called once.

Shownum () slot function
def shownum (self):
Count = Count + 1
Print (count)

PYQT5 Series Tutorials (eight) use of timer Qtimer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.