from tkinter import *
from random import randint
from math import sqrt
def create_bubble():
x = WIDTH + GAP
y = randint(0, HEIGHT)
r = randint(MIN_BUB_R, MAX_BUB_R)
id1 = c.create_rectangle(x - r, y - r, x + r, y + r, outline="light blue", fill=color)
bub_id.append(id1)
bub_r.append(r)
bub_speed.append(randint(1, MAX_BUB_SPD))
def buton():
color = 'green'
HEIGHT = 500
WIDTH = 800
window = Tk()
window.title("Distrugatorul de bule")
c = Canvas(window, width=WIDTH, height=HEIGHT, bg="darkblue")
c.pack()
color = 'blue'
bub_id = list()
bub_r = list()
bub_speed = list()
MIN_BUB_R = 10
MAX_BUB_R = 30
MAX_BUB_SPD = 10
GAP = 100
b = Button(window, text="change", command = buton)
b.pack()
mainloop()
BUB_CHANCE = 10
if randint(1, BUB_CHANCE) == 1:
create_bubble()
颜色是变量,当启动程序并按下按钮时,气泡仍然保持蓝色。我该怎么办? 按钮不起作用或为什么会发生这种情况?