我是编程新手,我似乎不知道如何让“konto”不断更新,而不是在一段时间内循环。while循环的问题是它不允许输入新按钮,因为它会冻结窗口。你知道吗
我试过让“konto”成为本地的,把代码分成不同的函数,改变循环样式。Break退出循环,这样“konto”就不会更新。你知道吗
konto = 100
roulette_window = Tk()
def roulette(chosen_color, sats, konto):
while True:
x = randint(0, 36)
if x == 0:
green_num = x
print(green_num, 'Green')
color = ('Green')
if color and chosen_color == 'Green':
win_amount = 35 * int(sats)
elif (x % 2) == 0:
red_num = x
print(red_num, 'Red')
color = ('Red')
if color and chosen_color == 'Red':
win_amount = 2 * int(sats)
elif (x % 2) == 1:
black_num = x
color = ('Black')
print(black_num, 'Black')
if color and chosen_color == 'Black':
win_amount = 2 * int(sats)
if not color == chosen_color:
win_amount = 0
konto = konto - int(sats) + int(win_amount)
print(konto)
def bet_black():
sats = bet_input.get(1.0, END)
chosen_color = 'Black'
bet_input.delete(1.0, END)
roulette(chosen_color, sats, konto)
def bet_red():
我想能够调用函数“轮盘赌”一次,例如赌黑按钮点击,然后点击赌红后一个循环,而仍然有更新的“konto”变量。你知道吗
首先,您的变量
konto
是一个全局变量,您需要向python表明它是全局变量。将方法更改为:Python中的变量具有作用域规则,这些规则决定了它们的有效位置。任何时候,只要将变量指定给某个变量,就会创建该变量的本地版本,除非已将其显式标记为全局变量。你知道吗
其次,我不知道为什么这里有
while True
结构。这将导致一个无限循环,除非您break
退出它或return
。你知道吗相关问题 更多 >
编程相关推荐