I'm making a text based adventure 'heist' game in python. I've designed a GUI for it, which is controlled using four buttons which change text and command. I also included a few text boxes to show the player's current inventory, score and money available.
However, when the current money available (money
) score is supposed to be inserted into the relevant box (MoneyAvailableTextBox
), it is also inserted into the HeistAwardTextBox
.
The same problem appears when I try to update the heist award box (HeistAwardTextBox
), where the heist award score (heistaward
) is inserted into both heist award box (HeistAwardTextBox
) and money available box (MoneyAvailableTextBox
).
Here is an edited sample of the relevant code.
import tkinter as tk
from tkinter import*
import pygame
pygame.init()
temp = Tk()
temp.title('EdRevGames')
temp.geometry('1352x752+0+0')
temp.configure(background = 'white')
#This is how much money the player currently has
money = 10
heistaward = 0
#This updates how much money the user has
def updateStats():
MoneyAvailableTextBox.delete('0', END)
MoneyAvailableTextBox.insert(tk.INSERT, money)
HeistAwardTextBox.delete('0', END)
HeistAwardTextBox.insert(tk.INSERT, heistaward)
# These are the text boxes and labels
MoneyLabel = Label(temp, font=('arial', 14, 'bold'), text = 'Money Available', bg='black', fg = 'white', bd = 5, justify = LEFT)
MoneyLabel.grid(row = 0, column = 0)
MoneySignLabel = Label(temp, font=('arial', 14, 'bold'), text = '£', bg='black', fg = 'white', bd = 5, justify = LEFT)
MoneySignLabel.grid(row = 1, column = 0, sticky = W)
MoneyAvailableTextBox = Entry(temp, font=('arial', 14, 'bold'), bg='White', fg = 'Black', bd = 5, width = 10, borderwidth = 4, justify = CENTER, text = '£')
MoneyAvailableTextBox.grid(row = 1, column = 0, pady = 10)
HeistAwardLabel = Label(temp, font=('arial', 14, 'bold'), text = 'Heist Award', bg='black', fg = 'white', bd = 5, justify = LEFT)
HeistAwardLabel.grid(row = 2, column = 0)
HeistAwardSignLabel = Label(temp, font=('arial', 14, 'bold'), text = '£', bg='black', fg = 'white', bd = 5, justify = LEFT)
HeistAwardSignLabel.grid(row = 3, column = 0, sticky = W)
HeistAwardTextBox = Entry(temp, font=('arial', 14, 'bold'), bg='White', fg = 'Black', bd = 5, width = 10, borderwidth = 4, justify = CENTER, text = '£')
HeistAwardTextBox.grid(row = 3, column = 0, pady = 10)
#Button which when pressed updates money avaible
Button1 = Button(temp, font=('arial', 14, 'bold'), bg='blue', fg = 'white', bd = 1, width = 17, height = 2, justify = CENTER, command = updateStats, text = 'Update')
Button1.grid(row = 4)
temp.mainloop()
Is there something I'm missing? Or anyway to solve this?