I'm working on a clicker game in Tkinter that is very different from Bubble Blaster:
from tkinter import *
from tkinter.messagebox import *
from time import sleep
import math
extraCashCost = 50
class AppUI(Frame):
def __init__(self, master=None):
self.saves = open("self.saves.log", "r")
self.savesEdit = open("self.saves.log", "a")
self.saveSring = ''.join(self.saves.read())
Frame.__init__(self, master, relief=SUNKEN, bd=2)
self.menubar = Menu(self)
menu = Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="Game", menu=menu)
menu.add_command(label="Open Store", command=lambda:storewin())
menu.add_command(label="Browse Saves", command=lambda:showinfo("WIP", "This is a work in progress game"))
menu = Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="Edit", menu=menu)
menu.add_command(label="Open the developer window", command=lambda:devwin())
try:
self.master.config(menu=self.menubar)
except AttributeError:
# master is a toplevel window (Python 1.4/Tkinter 1.63)
self.master.tk.call(master, "config", "-menu", self.menubar)
self.money = 0
self.cashGet = 1
self.moneyShow = Label(root, text="$" + str(self.money))
self.moneyGet = Button(root, text="Get Money!", command=lambda:cashin(self.cashGet))
self.moneyGet.pack(side=BOTTOM)
self.moneyShow.pack()
def cashin(cash):
sleep(0.125)
app.money += int(cash)
app.moneyShow.config(text="$" + str(app.money))
def devcashadd(moneyz):
app.money += int(moneyz)
app.moneyShow.config(text="$" + str(app.money))
def devwin():
dev = Tk()
dl = Label(dev, text="Welcome to the developer window. \n Here you will have access to developer tools. \n This is available only in developer versions.").pack()
mcl = Label(dev, text="Enter a number below and press the button under it to get free money!")
mc = Entry(dev)
mca = Button(dev, text="Get Money", command=lambda:devcashadd(mc.get())).pack()
mc.pack()
dev.mainloop()
def ec(cs):
global extraCashCost
if app.money >= extraCashCost:
extraCashCost = math.ceil(extraCashCost * 2.2)
app.money -= extraCashCost
app.cashGet *= 1.6
app.moneyShow.config(text="$" + str(app.money))
cs.config(text="$" + str(extraCashCost))
def storewin():
global extraCashCost
store = Tk()
extraCashShow = Label(store, text="$" + str(extraCashCost))
extraCash = Button(store, text="More Money!", command=lambda:ec(extraCashShow))
extraCashShow.pack()
extraCash.pack()
store.mainloop()
root = Tk()
app = AppUI(root)
app.pack()
root.mainloop()
It is going to be on GitHub soon. Anything that could be changed to make it run faster?
And also, how can I put custom styles on the widgets?
Like background gradients, images, etc...