Python Forum
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clicker game counter help
#1
You guys helped me alot, you made my life easy with your help and code. So i ask again. I am trying to create clicker game where you click on some button and you get +1 score but I am trying to create this in tkinter without pygame. I know it can be done, but I dont know how to get the score work. 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()
Reply


Messages In This Thread
Clicker game counter help - by JohnNo - Apr-30-2017, 05:12 AM
RE: Clicker game counter help - by JohnNo - Apr-30-2017, 09:24 AM
RE: Clicker game counter help - by nilamo - May-02-2017, 04:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pygame error in my clicker game CrazyMakes 2 2,626 Apr-19-2020, 03:04 AM
Last Post: Windspar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020