如何在本地增加全局变量的数量?
我正在使用 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 方法完全空白,我似乎记得它非常相似。
I'm writing a program using PyQt and I'm trying to figure out a way to keep adding to a global variable every time a particular button is clicked. This way if my global is 0 then the third time the button is clicked my global would equal 3. Here's the relevant code.
# 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()
This is pretty easy in C but I'm completely blanking on the python method which I seem to recall was very similiar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用全局语句
use the global statement