如何局部增加全局变量的量?

2024-06-26 14:53:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用PyQt编写一个程序,并试图找出一种方法,在每次单击某个特定的按钮时,都能不断地向全局变量添加数据。这样,如果我的全局设置为0,那么第三次单击该按钮时,我的全局值将等于3。这是相关代码。在

# from the main window class

QtCore.QObject.connect(self.pushButton_17, QtCore.SIGNAL("clicked()"), self.CadDraw)

def CadDraw(self):
    myGlobal +=1 #the previous value from the last time CadDraw was called plus 1
    DoStuff()

这在C语言中很容易实现,但我完全忽略了python方法,我记得它非常相似。在


Tags: the数据方法代码fromself程序main