'Im trying to add increase a level when you reach a certain amount of clicks tkinter
I'm making a simple clicking game and the I can't seem to figure out how to increase the level when I reach a certain amount of clicks. For example, every time a user clicks a button they gain clicks, and when they reach a certain amount of clicks they level up
If anyone knows how to fix this problem it would be wonderful if you share!
Here is the code:
from tkinter import *
import tkinter as tk
import time
from PIL import ImageTk, Image
root = Tk()
root.geometry('450x350')
root.title('Clicking Game')
root.configure(bg='blue')
level = 1
clicks = 0
label = tk.Label(root, text='Experiance: '+str(clicks), background='blue', foreground='white')
level_label = tk.Label(root,background='blue',foreground='white' ,text='Level: '+str(level))
photo = PhotoImage(file=r"C:\Users\mosta\Downloads\python-transparent-background.png")
def on_click():
global clicks, levels
clicks += 1
label.config(text='Experiance: '+str(clicks))
level_label.config(text='Level: '+str(level))
if clicks >= 100:
clicks += 10
if clicks >= 50:
clicks += 5
if clicks >= 10:
clicks += 2
if clicks >= 200:
clicks += 20
if clicks >= 300:
clicks += 30
if clicks >= 400:
clicks += 40
if clicks >= 500:
clicks += 50
if clicks >= 600:
clicks += 60
if clicks >= 10000:
clicks += 1
label.pack(side=TOP)
label.config(font=('Arial', 30, 'bold', 'italic'))
level_label.pack(side=BOTTOM)
level_label.config(font=('Arial', 30, 'bold', 'italic'))
button = tk.Button(root,borderwidth=10,width=60,height=60, text = 'Click Me !', image = photo, command=on_click)
button.place(x=625, y=300)
#leveling system
def level_claim():
global level, clicks
if clicks >= 10000:
claim_level.pack(side=RIGHT)
level += 1
claim_level = tk.Button(text='Claim Level', bg='pink', foreground='red', command=level_claim)
level_congrats = tk.Label(root, text='Congratulations You have reached level 2!\n'
'Keeping leveling up to unlock more features')
root.mainloop()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
