我可以在循环中仅定义整数吗?
这是我的代码中的一部分,每次按弹出窗口上的确定按钮时,我都会运行回调,因此我只想将计数定义一次。之后,我需要将“ count = 0”行排除在循环中。当我将其放在循环外时,即使使用全局,它也会给我一个错误,说它不知道什么是计数。有什么办法可以解决这个问题? (这是我的代码)
def callback():
count = 0
value = int(entry_field.get())
entry_field.delete("0", tk.END)
if value in plusOne:
count += count + 1
print(count)
谢谢
This is a piece of my code, I run the callback every time I press the ok button on my pop-up so I only want count to be defined once. After that I need to exclude the line "count = 0" from being looped. When I put it outside of the loop, even using global, it gives me an error saying it doesn't know what count is. Any way I could fix this? (Here is my code)
def callback():
count = 0
value = int(entry_field.get())
entry_field.delete("0", tk.END)
if value in plusOne:
count += count + 1
print(count)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其定义为全球?:
define it as global?: