Python 触摸并影响任何物体

Python 触摸并影响任何物体,python,kivy,Python,Kivy,。。。 如何给出函数路径? 我找不到解决地址问题的方法。 有人知道怎么解决这个问题吗? 当我只点击绿色区域时,我想在白色区域中操作按钮。 ''蟒蛇 main.py ''' 转轮1.kv “基维 : 大小提示:1,1 pos_提示:{“x”:0,“y”:0} 画布: 颜色: rgba:0.9,0.9,0.9,1 矩形: 大小:self.size 证券交易委员会: Vec: : 尺寸提示:1,0.5 pos_提示:{“x”:0,“y”:0} 画布: 颜色: rgba:0.9,0.8,0.7,1

。。。 如何给出函数路径? 我找不到解决地址问题的方法。 有人知道怎么解决这个问题吗? 当我只点击绿色区域时,我想在白色区域中操作按钮。

''蟒蛇 main.py

'''

转轮1.kv

“基维

:
大小提示:1,1
pos_提示:{“x”:0,“y”:0}
画布:
颜色:
rgba:0.9,0.9,0.9,1
矩形:
大小:self.size
证券交易委员会:
Vec:
:
尺寸提示:1,0.5
pos_提示:{“x”:0,“y”:0}
画布:
颜色:
rgba:0.9,0.8,0.7,1
矩形:
大小:self.size
按钮:
身份证号码:secbut
文本:“单击”
尺寸提示:0.5,0.5
:
尺寸提示:1,0.5
pos_提示:{“x”:0,“y”:0.5}
画布:
颜色:
rgba:0.2,0.8,0.1,1
矩形:
大小:self.size
'''


我找不到如何解决寻址问题。

您需要检查触摸是否与您关心的区域发生碰撞

if self.collide_point(*touch.pos):
    self.ids.secbut.disabled = True

有点尴尬,但你可以通过在你的
Sec
中添加一个
id
来实现,如下所示:

<Area>:
    size_hint: 1, 1
    pos_hint: {"x":0,"y":0}
    canvas:
        Color:
            rgba:0.9,0.9,0.9,1
        Rectangle:
            size:self.size    
    Sec:
        id: sec
    Vec:

谢谢,但我得到一个警告。AttributeError:“super”对象在一个类中没有属性“getattr”绿色区域,按钮在另一个类中。在
Vec
中的
on\u touch\u down()
方法中,您必须使用
Sec
的实例来访问
ID
,但您使用的是类,而不是实例。@JohnAnderson我理解,但我不知道如何使用它。我是这一页的新手。我正在自学英语。。
if self.collide_point(*touch.pos):
    self.ids.secbut.disabled = True
<Area>:
    size_hint: 1, 1
    pos_hint: {"x":0,"y":0}
    canvas:
        Color:
            rgba:0.9,0.9,0.9,1
        Rectangle:
            size:self.size    
    Sec:
        id: sec
    Vec:
class Vec(RelativeLayout):
    """ This is green area
    I want the button to disable when the green area is clicked.
    """
    def on_touch_down(self,touch):
        if self.collide_point(*touch.pos):
            App.get_running_app().root.ids.sec.ids.secbut.disabled = True