Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Counter clicker

I got some code for my counter from someone, it is working console prints out 1 2 3 4... but I dont know how to make a label, that shows the value and i need to store it somewhere like
a = //That value//
so I can later use it in my shop like if a is = 20 he can buy something that will change how much points he gets, so like if a = 20 he buys that and now the score is like this 2 4 6.... and global value of the counter so if I change the value to 3 the counter will count like this 3 6 9....So I ask if someone here can help me make simple counter/adder to label and store the value globaly so i can refer to it anywhere, if it is possible I dont understand __init__ and self., so if someone can do it without it, it would be really great, but i can do with __init__ but for me it is very hard i am learing python and still i dont know what that is, even if I look on multiple sites that explained it, still I dont know.
Here is the counter but I dont know how to get the value global and refer to it anywhere.
import tkinter as tk
class Counter(object):
def __init__(self, start: int = 0):
self.value = start
def add(self) -> int:
if self.value < 900:
self.value += 1
print(self.value)
return self.value
clicks = Counter()
root = tk.Tk()
tk.Button(root, text="click me!", command=clicks.add).pack()
root.mainloop()
by

1 Answer

Bharatv4tg1
Have you tried calling the function, instead of just referring to it? ie: root.destroy()

I don't think using global variables is a good idea. It solves the immediate issue while making the next thing more complicated.

Login / Signup to Answer the Question.