谢谢你帮我解决。所以我赚了一个可变的钱,它显示了 100。
现在代码必须增加或减少它。
这个小程序几乎可以工作了,但我不知道得分。一世
有一个显示分数的变量,但它保持在 100。重启函数
也不工作。
from tkinter import *
import random
import time
#main settings
money = 100
def get_money(value):
global money
money = value
output.delete(0.0, END)
tk = Tk()
tk.title('Gamble game')
tk.configure(background='black')
#gameoutput box
output = Text(tk, width=50, height=8, wrap=WORD, bg='white')
output.grid(row=1, column=0, sticky=W)
#restart game, reset money
Button(tk, text='Restart',width=10, command=get_money(100)).grid(row=3,\
column=0, sticky=W)
#money
Label(tk, text=money, bg='black', fg='white', font='none 12
bold').grid(row=0,\
column=0, sticky=W)
#game start_round
def start_round():
output.delete(0.0, END)
output.insert(END, 'Here are your numbers:\n')
for x in range(0, 3):
x = random.randint(0, 20)
output.insert(END, x)
time.sleep(0.2)
try:
if x == 20:
output.insert(END, '\nYou won!\n')
get_money += 50
else:
output.insert(END, '\nLost!\n')
get_money = money - 10
except:
output.insert(END, 'Something went wrong')
Button(tk, text='Enter',width=10, command=start_round).grid(row=2,
column=0, sticky=W)
#exit game
def exit_window():
tk.destroy()
exit()
Button(tk, text='Exit',width=10, command=exit_window).grid(row=4,
column=0, sticky=W)
#main loop
tk.mainloop()
相关分类