Спасибо, что помогли мне.Итак, я заработал переменные деньги, и они показывают 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()