'Kivy: How do I place a resizable button in the RH bottom corner, with spacing?
I'm new to Kivy, and want to use it for developing a mobile 'Event Card' app.
I've done the basic layout I believe, but the button at the bottom RH corner eludes me. I have tried various ways to make the button resizable and with spacing around it, but all to no avail. My best effort is shown below: the button size never changes, and nor does the padding. The latter is because I don't see how to change the padding value 'on the fly'.
Thanks in advance for any assistance.
chaosui.kv
#:kivy 1.10.0
<NextCardButton@MDRaisedButton>:
size_hint: [None, None]
size: [100, 100]
<EventCardLayout@BoxLayout>:
orientation: "vertical"
<EventBottomLayout@AnchorLayout>:
anchor_x: 'right'
anchor_y: 'bottom'
# To Do: 'padding' needs to be relative!
padding: ('10dp', '10dp', '10dp', '10dp')
adaptive_size: True
MDRaisedButton:
# To Do: move button to right.
text: 'Next'
EventCardLayout:
MDToolbar:
title: "Events"
right_action_items: [["menu", lambda x: app.callback(x)]]
elevation: 10
MDLabel:
text: "Order"
halign: "center"
font_style: "H2"
theme_text_color: "Secondary"
MDLabel:
text: "Enemy Spotted!"
halign: "center"
font_style: "H3"
theme_text_color: "Primary"
MDLabel:
text: "Advance towards nearest opponent(s)"
halign: "center"
font_style: "H4"
theme_text_color: "Primary"
MDLabel:
text: "Subordinate CR required to cancel order"
halign: "center"
font_style: "H5"
theme_text_color: "Primary"
EventBottomLayout:
chaosapp.py
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.metrics import dp
from kivymd.uix.menu import MDDropdownMenu
class ChaosApp(MDApp):
def build(self):
self.title = 'CHAnce Organising System'
menu_items = [
{
"viewclass": "OneLineListItem",
"text": f"{item}",
"height": dp(56),
"on_release": lambda x=f"{item}": self.menu_callback(x),
} for item in ('Import', 'Shuffle', 'Reset', 'Abort')
]
self.menu = MDDropdownMenu(
items=menu_items,
width_mult=4,
)
return Builder.load_file('chaosui.kv')
def callback(self, button):
self.menu.caller = button
self.menu.open()
def menu_callback(self, text_item):
self.menu.dismiss()
# Snackbar(text=text_item).open()
ChaosApp().run()
Solution 1:[1]
Found it!
Kivy TypeError unsupported operand type
size: .5 * self.parent.width, .5 * self.parent.height
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Richard Prosser |