问题描述
我正在用 python 制作一个基于文本的冒险“抢劫”游戏。我为它设计了一个 GUI,它使用四个更改文本和命令的按钮进行控制。我还添加了一些文本框来显示玩家当前的库存、分数和可用资金。
然而,当应将当前可用货币 (money
) 分数插入相关框 (MoneyAvailableTextBox
) 时,也 em> 插入到 HeistAwardTextBox
中。
当我尝试更新抢劫奖励箱 (HeistAwardTextBox
) 时出现同样的问题,其中抢劫奖励分数 (heistaward
) 被插入到两个抢劫奖励箱 (HeistAwardTextBox
) 中和可用现金框 (MoneyAvailableTextBox
)。
这是相关代码的编辑示例。
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,text = '£',justify = LEFT)
MoneySignLabel.grid(row = 1,column = 0,sticky = W)
MoneyAvailableTextBox = Entry(temp,bg='White',fg = 'Black',width = 10,borderwidth = 4,justify = CENTER,text = '£')
MoneyAvailableTextBox.grid(row = 1,pady = 10)
HeistAwardLabel = Label(temp,text = 'Heist Award',justify = LEFT)
HeistAwardLabel.grid(row = 2,column = 0)
HeistAwardSignLabel = Label(temp,justify = LEFT)
HeistAwardSignLabel.grid(row = 3,sticky = W)
HeistAwardTextBox = Entry(temp,text = '£')
HeistAwardTextBox.grid(row = 3,pady = 10)
#Button which when pressed updates money avaible
Button1 = Button(temp,bg='blue',bd = 1,width = 17,height = 2,command = updateStats,text = 'Update')
Button1.grid(row = 4)
temp.mainloop()
有什么我遗漏的吗?或者无论如何解决这个问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)