如何使用全局变量递减现有的增量循环?

时间:2018-08-22 14:12:33

标签: python

这是给我正在做的小项目的。在减量时显示值时出现错误。我正在通过树莓派使用python进行编码,而这部分在我的qt4 gui类的功能代码之内。

z = 0 
def increment:
global z 
if self.ui.pushButton_2.isChecked():
   z += 1
elif self.ui.pushButton_3.isChecked():
   z -= 1

def SpinMotor(self):
   GPIO.setup(7, GPIO.OUT) 
   GPIO.setup(18, GPIO.OUT)
   p1 = GPIO.PWM(7, 1600)
   GPIO.output(18, False)
   if self.ui.pushButton_2.isChecked():
       self.increment()
       f = z*0.00119
       x = 0
       x += 1
       x1 = str(f)
       self.ui.t1.setText(x1)


       GPIO.output(7, x)
       p1.start(1)
       time.sleep(0.01)
       x -= 1


       p1.stop
    else:
       print "button is released"

 def SpinMotor2(self):
   GPIO.setup(7, GPIO.OUT) 
   GPIO.setup(18, GPIO.OUT)
   p1 = GPIO.PWM(7, 1600)
   GPIO.output(18, True)
   if self.ui.pushButton_3.isChecked():
       self.increment()
       f = z*0.00119
       x = 0
       x += 1
       x1 = str(f)
       self.ui.t1.setText(x1)


       GPIO.output(7, x)
       p1.start(1)
       time.sleep(0.01)
       x -= 1


       p1.stop
    else:
       print "button is released"

问题在于输出仅在pushbutton_3事件期间添加。请帮助。 :(

0 个答案:

没有答案