community
community copied to clipboard
KIVY AnchorLayout How can i put 2 children widget in 1 AnchorLayout? xd
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
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.
That works but still reaming some spaces in the AnchorLayout where we can not use, aren't we? Very confuscing
That works but still reaming some spaces in the AnchorLayout where we can not use, aren't we? Very confuscing
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.
thank u , going on that way and shouting there. hope meet u there.
Both do not work for me because of internationnal problems, thanks anyway, that 2 links are awesome.
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()
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.
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()
Great, thanks Cool, very cool
@xinzhengzhangCHN please close this issue.
👋 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.