How to quit the program in while loop using push-button in PyQt

后端 未结 2 1390
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-19 04:42

I have the following code which will start after clicking the \'Start\' button in PyQt:

def Start(self):
  import time
  import os
  import RPi.GPIO as GPIO
         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-19 05:22

    There is no need to do anything other than what I suggested in your other question on this topic: just use processEvents. As long as you can call it frequently enough (but not too frequently), it should do exactly what you want. Using your second example, the following works fine for me:

      def Start(self):
        if not self.started:
            self.started = True
            self.StartLoop()
    
      def Stop(self):
        if self.started:
            self.started = False
    
      def StartLoop(self):
        DEBUG = 1
        while self.started:
            print "LED on "
            time.sleep(0.05)
            print "LED off "
            time.sleep(0.085)
            QtGui.qApp.processEvents()
    

提交回复
热议问题