Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

python - How use BoxLayout from KivyMD

Why can I move the button only horizontally using the vertical orientation of BoxLayout, and only vertically using the horizontal orientation? For example:

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()

Horizontal orientation, also the default orientation:

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()

How to move widgets freely on both axes? Help please

question from:https://stackoverflow.com/questions/65841119/how-use-boxlayout-from-kivymd

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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()

https://kivy.org/doc/stable/api-kivy.uix.floatlayout.html

https://kivy.org/doc/stable/api-kivy.uix.boxlayout.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...