我想做一个类似 android-lock 的东西,所以我有 2 个按钮的图像(按钮正常,按下按钮)。
我在每个图像上定义了一个函数 on_touch_down,所以当我按下它时,它将源更改为按下的按钮,并且 on_touch_up 将其更改回正常状态。但是每次我按下屏幕的任何部分时,它都会立即更改所有按钮。
我怎样才能让它在我按下它时只改变每个按钮,而不是在我按下任何地方时改变一切?
这是我的kv文件:
Manager:
Principal:
<Principal>:
GridLayout:
cols: 3
Image:
id: '1'
size: 30,30
source: 'button.png'
on_touch_down: self.source = 'button_press.png'
on_touch_up: self.source = 'button.png'
allow_strech: True
Image:
id: '2'
size: 30,30
source: 'button.png'
on_touch_down: self.source = 'button_press.png'
on_touch_up: self.source = 'button.png'
allow_strech: True
Image:
id: '3'
size: 30,30
source: 'button.png'
on_touch_down: self.source = 'button_press.png'
on_touch_up: self.source = 'button.png'
allow_strech: True
Image:
id: '4'
size: 30,30
source: 'button.png'
on_touch_down: self.source = 'button_press.png'
on_touch_up: self.source = 'button.png'
allow_strech: True
Image:
id: '5'
size: 30,30
source: 'button.png'
on_touch_down: self.source = 'button_press.png'
on_touch_up: self.source = 'button.png'
allow_strech: True
Image:
id: '6'
size: 30,30
source: 'button.png'
on_touch_down: self.source = 'button_press.png'
on_touch_up: self.source = 'button.png'
allow_strech: True
Image:
id: '7'
size: 30,30
source: 'button.png'
on_touch_down: self.source = 'button_press.png'
on_touch_up: self.source = 'button.png'
allow_strech: True
Image:
id: '8'
size: 30,30
source: 'button.png'
on_touch_down: self.source = 'button_press.png'
on_touch_up: self.source = 'button.png'
allow_strech: True
Image:
id: '9'
size: 30,30
source: 'button.png'
on_touch_down: self.source = 'button_press.png'
on_touch_up: self.source = 'button.png'
allow_strech: True