变量的 tkinter 问题不会向上、向下或重置

谢谢你帮我解决。所以我赚了一个可变的钱,它显示了 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()


qq_花开花谢_0
浏览 169回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python