如何在Python 3上使用Tkinter更新GUI?

时间:2015-12-03 10:29:55

标签: python tkinter

我正在制作一个文本游戏,我正在利用Tkinter进行GUI以显示玩家的统计数据。如果有人可以帮助我每隔几秒钟更新一次GUI以显示最新的统计数据,那将非常感激。我现在将发布代码:

def Stats(): # The function for the GUI, used later in threading
global name
global strength
global intel
global hp
global weapon
global weaponBonus
global armour
global defence
stats = tkinter.Tk()
stats.title ("Stats")
nameLabel = tkinter.Label(stats, text=" Name = %s " % name, font=("Papyrus", 16), bg="#c29970")
hpLabel = tkinter.Label(stats, text=" HP = %s " % hp, font=("Papyrus", 16), bg="#ba8c5f")
strengthLabel = tkinter.Label(stats, text=" Strength = %s " % strength, font=("Papyrus", 16), bg="#b27f4d")
intelLabel = tkinter.Label(stats, text=" Intelligence = %s " % intel, font=("Papyrus", 16), bg="#a07245")
weaponLabel = tkinter.Label(stats, text=" Weapon = %s (Strength Bonus = %s) " % (weapon, weaponBonus), font=("Papyrus", 16), bg="#8f663d")
armourLabel = tkinter.Label(stats, text=" Armour = %s (Defence = %s) " % (armour, defence), font=("Papyrus", 16), bg="#7d5935")
nameLabel.pack(side=tkinter.LEFT)
hpLabel.pack(side=tkinter.LEFT)
strengthLabel.pack(side=tkinter.LEFT)
intelLabel.pack(side=tkinter.LEFT)
weaponLabel.pack(side=tkinter.LEFT)
armourLabel.pack(side=tkinter.LEFT)
stats.mainloop()

StatsRun = threading.Thread(target = Stats) # The threading program
StatsRun.start()

0 个答案:

没有答案