Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
xinzhengzhangCHN opened this issue May 23, 2024 · 12 comments
Closed
Labels

Comments

@xinzhengzhangCHN
Copy link

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

@ElliotGarbus
Copy link
Contributor

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.

@xinzhengzhangCHN
Copy link
Author

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

1 similar comment
@xinzhengzhangCHN
Copy link
Author

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

@ElliotGarbus
Copy link
Contributor

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.

@xinzhengzhangCHN
Copy link
Author

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

@xinzhengzhangCHN
Copy link
Author

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

@ElliotGarbus
Copy link
Contributor

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

@xinzhengzhangCHN
Copy link
Author

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.

@ElliotGarbus
Copy link
Contributor

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

@xinzhengzhangCHN
Copy link
Author

Great, thanks
Cool, very cool

@ElliotGarbus
Copy link
Contributor

@xinzhengzhangCHN please close this issue.

@misl6 misl6 added the support label Jun 1, 2024
Copy link

github-actions bot commented Jun 1, 2024

👋 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 github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants