所以基本上这个代码应该做的是有一个按钮,当点击它时,将变量z(= 0.5)更改为z - 0.5。
def change(self, obj):
z = z - 0.1
return z
def __init__(self, **kwargs):
x = randint(1,10)
print (x)
y = 'water.png'
if x==1:
y = 'a.png'
if x==2:
y = 'b.png'
if x==3:
y = 'c.png'
if x==4:
y = 'd.png'
if x==5:
y = 'e.png'
if x==6:
y = 'f.png'
if x==7:
y = 'g.png'
if x==8:
y = 'h.png'
if x==9:
y = 'i.png'
if x==10:
y = 'j.png'
z = 0.5
super(MyBackground, self).__init__(**kwargs)
with self.canvas:
btnworking = Button(text = "opacity50%")
btnworking.bind(on_press=change)
self.add_widget(btnworking)
Color(1, 1, 1, 0.5)
self.bg = Rectangle(source=y, pos=self.pos, size=self.size)
self.bind(pos=self.update_bg)
self.bind(size=self.update_bg)
def update_bg(self, *args):
self.bg.pos = self.pos
self.bg.size = self.size
它表示当我在按钮
上调用时,名称更改未定义