community icon indicating copy to clipboard operation
community copied to clipboard

KIVY AnchorLayout How can i put 2 children widget in 1 AnchorLayout? xd

Open xinzhengzhangCHN opened this issue 1 year ago • 9 comments
trafficstars

I tried times to put 2 button in 1 AnchorLayout, no a way. Tell me a way if u find it, because i wanna it so much, i have alreadu tried more 10 times so that my deasire is so high and i want it so much. Thanks

xinzhengzhangCHN avatar May 23 '24 01:05 xinzhengzhangCHN

Put the two buttons in a BoxLayout, put the BoxLayout in the AnchorLayout.

Ask in one of the support forums and I’ll show you an example.

ElliotGarbus avatar May 23 '24 02:05 ElliotGarbus

That works but still reaming some spaces in the AnchorLayout where we can not use, aren't we? Very confuscing

xinzhengzhangCHN avatar May 23 '24 05:05 xinzhengzhangCHN

That works but still reaming some spaces in the AnchorLayout where we can not use, aren't we? Very confuscing

xinzhengzhangCHN avatar May 23 '24 05:05 xinzhengzhangCHN

The official support forums are: https://groups.google.com/g/kivy-users https://discord.com/invite/eT3cuQp

There is also a support forum on Reddit: https://www.reddit.com/r/kivy/ Please take this support question to one of these forums. This area on Github is for reporting bugs.

ElliotGarbus avatar May 23 '24 13:05 ElliotGarbus

thank u , going on that way and shouting there. hope meet u there.

xinzhengzhangCHN avatar May 24 '24 03:05 xinzhengzhangCHN

Both do not work for me because of internationnal problems, thanks anyway, that 2 links are awesome.

xinzhengzhangCHN avatar May 24 '24 03:05 xinzhengzhangCHN

Here is an example:

from kivy.app import App
from kivy.lang import Builder

kv = """
AnchorLayout:
    BoxLayout:
        size_hint: None, None
        size: dp(300), dp(48)
        Button:
            text: 'One'
        Button:
            text: 'Two'
"""


class TwoButtonAnchorViewApp(App):
    def build(self):
        return Builder.load_string(kv)


TwoButtonAnchorViewApp().run()

ElliotGarbus avatar May 24 '24 04:05 ElliotGarbus

thanks Oh, dear brother Elliot Garbus, i mean why not put AnchorLayout's attribution anchor_x: "left" anchor_y: "top" in there? They only work for one item. How to use it for 2 item?

Example: AnchorLayout: anchor_x: "left" anchor_y: "top" Label: id: phonetic font_name: "DejaVuSans.ttf" size_hint: None, None size: 30, 22 color: 0, 0, 0, 1 This is for one item. How about i put 2 in there? which 1 is in the left and bottom , and 1 is in the right top for 1 AnchorLayout? This is what i am confusing bro. ` AnchorLayout:

                Label:
                    id: phonetic
                    font_name: "DejaVuSans.ttf"
                    size_hint: None, None
                    size: 30, 22
                    color: 0, 0, 0, 1
                    anchor_x: "left"
                    anchor_y: "top" 
                Label:
                    id: phonetic2
                    font_name: "DejaVuSans.ttf"
                    size_hint: None, None
                    size: 30, 22
                    color: 0, 0, 0, 1
                    anchor_x: "right"
                    anchor_y: "bottom"     ` Of course this won't work, because anchor_x and y are AnchorLayout's attribute not Label's. How to make it work ?

pls show me, bro, thanks.

xinzhengzhangCHN avatar May 24 '24 06:05 xinzhengzhangCHN

Here are 2 ways to position the widgets the way you would like. One with AnchorLayouts, the other using pos_hints in a FloatLayout.

from kivy.app import App
from kivy.lang import Builder

kv = """
FloatLayout:
    AnchorLayout:
        anchor_x: "left"
        anchor_y: "top" 
        Label:
            id: phonetic
            # font_name: "DejaVuSans.ttf"
            size_hint: None, None
            size: 30, 22
            # color: 0, 0, 0, 1
            text: 'LT'
    AnchorLayout:
        anchor_x: "right"
        anchor_y: "bottom"  
        Label:
            id: phonetic2
            # font_name: "DejaVuSans.ttf"
            size_hint: None, None
            size: 30, 22
            # color: 0, 0, 0, 1
            text: 'BR'
    # or use pos_hints in a FloatLayout or RelativeLayout
    Label:
        size_hint: None, None
        size: 30, 22
        text: 'BL'
        pos_hint: {'bottom':1, 'left': 1}
    Label:
        size_hint: None, None
        size: 30, 22
        text: 'TR'
        pos_hint: {'top':1, 'right': 1}
"""


class TwoButtonAnchorViewApp(App):
    def build(self):
        return Builder.load_string(kv)


TwoButtonAnchorViewApp().run()

ElliotGarbus avatar May 24 '24 14:05 ElliotGarbus

Great, thanks Cool, very cool

xinzhengzhangCHN avatar May 31 '24 01:05 xinzhengzhangCHN

@xinzhengzhangCHN please close this issue.

ElliotGarbus avatar May 31 '24 15:05 ElliotGarbus

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.

If you're having trouble installing Kivy, make sure to check out the installation docs for Windows, Linux and macOS.

Let us know if this comment was made in error, and we'll be happy to reopen the issue.

github-actions[bot] avatar Jun 01 '24 08:06 github-actions[bot]