是否有方法使用<;更改按钮属性;按钮>;但只是在一个特定的布局中
我不想在执行过程中更改大小,我只是不想为所有按钮编写它,只想在我的布局中编写一次
示例:在我下面的代码中,我想要更改MyLayout中所有按钮的大小,而不是LoadFilePicker中的按钮
科林
MyLayout:
Button:
pos_hint: {"x":0.05, "top":0.95}
text:"Import config"
on_release:
root.loadPicker()
Button:
pos_hint: {"x":0.2, "top":0.9}
text:"Poll A"
<LoadFilePicker>:
BoxLayout:
size: root.size
pos: root.pos
orientation: "vertical"
FileChooserListView:
id: filechooser
BoxLayout:
size_hint_y: None
height: 30
Button:
text: "Cancel"
on_release: root.cancel()
Button:
text: "Load"
on_release: root.load(filechooser.path, filechooser.selection)
下面是MyLayout类的定义
class MyLayout(FloatLayout):
def load(self, path, filename):
self.dismiss_popup()
db = DataBase(filename)
db.loadData()
def dismiss_popup(self):
self._popup.dismiss()
def loadPicker(self):
content = LoadFilePicker(load=self.load, cancel=self.dismiss_popup)
self._popup = Popup(title="Load file",content=content,size_hint=(0.9, 0.9))
self._popup.open()
有几种方法可以做到这一点,其中一种方法类似于MyLayout类中的以下方法:
您可以像这样子类化
Button
:然后在
MyLayout
中使用该子类:相关问题 更多 >
编程相关推荐