python - 如何使用 KivyMD 的 BoxLayout
问题描述
为什么我只能使用 BoxLayout 的垂直方向来水平移动按钮,而只能使用水平方向来垂直移动按钮?例如:
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
Screen:
BoxLayout:
orientation: 'vertical'
MDRaisedButton:
pos_hint: {'center_x': .3,'center_y': .5}
'''
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
Test().run()
水平方向,也是默认方向:
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
Screen:
BoxLayout:
orientation: 'horizontal'
MDRaisedButton:
pos_hint: {'center_x': .3,'center_y': .5}
'''
class FindWord(MDApp):
def build(self):
return Builder.load_string(KV)
FindWord().run()
如何在两个轴上自由移动小部件?请帮忙
解决方案
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
MDScreen:
MDBoxLayout:
adaptive_size: True
pos_hint: {'center_x': .3, 'center_y': .5}
MDRaisedButton:
text: "MDRaisedButton"
'''
class FindWord(MDApp):
def build(self):
return Builder.load_string(KV)
FindWord().run()
推荐阅读
- python-3.x - python 3字符串需要多少个byes?
- mysql - $GOPATH/go.mod 存在但不应该在 Docker 上
- sqlite - 如何在 Xamari Form 中使用 SQLite 为同一个表创建两个外键
- pytorch - 当我验证输入为非 0 维时,为什么 nn.CrossEntropyLoss 会抛出“TypeError:在 0-d 张量上迭代”?
- excel - 网站在网络抓取期间未识别多个表
- python - 使用语音识别器中的麦克风时获取 AttributeError:__enter__
- php - 在将项目移动到列表之前检查所有列表中的重复项
- python - 有时无法导入 NumPy
- javascript - 如何在我的 JavaScript 中添加搜索功能?
- php - 为什么我的其他输入值不会插入到我的数据库中?