'Can I define an integer in a loop only once?

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



Solution 1:[1]

define it as global?:

count = 0
def callback():
    global count
    value = int(entry_field.get())
    entry_field.delete("0", tk.END)


    if value in plusOne:
        count += count + 1
        print(count)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 testfile