我想在视频运行时禁用一个小部件,所以我创建了一个ScreenVideo类,我定义了一个layoutGrid,并在其中放置了带文件名的按钮。
当我调用on_press回调时,我得到的错误是:全局名称' layoutGrid'没有定义。
class ScreenVideo(Screen):
def __init__ (self,**kwargs):
super (ScreenVideo, self).__init__(**kwargs)
root = FloatLayout(size=(Window.width, Window.height))
layoutGrid = GridLayout(cols=1, row_force_default=True, row_default_height=70, size_hint_y=None)
layoutGrid .bind(minimum_height=layoutGrig.setter('height')) #for scroll
....
for filename in os.listdir(folder location):
filename2 = filename.replace(".mp4", "")
btn = Button(text=str(filename2), font_size='25sp', italic = True)
btn.bind(on_release=self.callback) #on_press
layoutGrid.add_widget(btn)
def callback(self, instance):
...
layoutGrid.disabled = True
由于
答案 0 :(得分:0)
使layoutGrid
成为您实例的属性:
class ScreenVideo(Screen):
def __init__ (self,**kwargs):
super (ScreenVideo, self).__init__(**kwargs)
root = FloatLayout(size=(Window.width, Window.height))
self.layoutGrid = GridLayout(cols=1, row_force_default=True, row_default_height=70, size_hint_y=None)
self.layoutGrid.bind(minimum_height=self.layoutGrid.setter('height')) #for scroll
....
for filename in os.listdir(folder location):
filename2 = filename.replace(".mp4", "")
btn = Button(text=str(filename2), font_size='25sp', italic = True)
btn.bind(on_release=self.callback) #on_press
self.layoutGrid.add_widget(btn)
def callback(self, instance):
...
self.layoutGrid.disabled = True