Banner¶
See also
A banner displays a prominent message and related optional actions.
Usage¶
from kivy.lang import Builder
from kivy.factory import Factory
from kivymd.app import MDApp
Builder.load_string('''
<ExampleBanner@Screen>
MDBanner:
id: banner
text: ["One line string text example without actions."]
# The widget that is under the banner.
# It will be shifted down to the height of the banner.
over_widget: screen
vertical_pad: toolbar.height
MDToolbar:
id: toolbar
title: "Example Banners"
elevation: 10
pos_hint: {'top': 1}
BoxLayout:
id: screen
orientation: "vertical"
size_hint_y: None
height: Window.height - toolbar.height
OneLineListItem:
text: "Banner without actions"
on_release: banner.show()
Widget:
''')
class Test(MDApp):
def build(self):
return Factory.ExampleBanner()
Test().run()
Banner type.
By default, the banner is of the type 'one-line'
:
MDBanner:
text: ["One line string text example without actions."]
To use a two-line banner, specify the 'two-line'
MDBanner.type
for the banner
and pass the list of two lines to the MDBanner.text
parameter:
MDBanner:
type: "two-line"
text:
["One line string text example without actions.", "This is the second line of the banner message."]
Similarly, create a three-line banner:
MDBanner:
type: "three-line"
text:
["One line string text example without actions.", "This is the second line of the banner message." "and this is the third line of the banner message."]
To add buttons to any type of banner,
use the MDBanner.left_action
and MDBanner.right_action
parameters,
which should take a list [‘Button name’, function]:
MDBanner:
text: ["One line string text example without actions."]
left_action: ["CANCEL", lambda x: None]
Or two buttons:
MDBanner:
text: ["One line string text example without actions."]
left_action: ["CANCEL", lambda x: None]
right_action: ["CLOSE", lambda x: None]
If you want to use the icon on the left in the banner, add the prefix ‘-icon’ to the banner type:
MDBanner:
type: "one-line-icon"
icon: f"{images_path}/kivymd_logo.png"
text: ["One line string text example without actions."]
Note
API - kivymd.uix.banner
¶
Bases:
kivymd.uix.card.MDCard
Indent the banner at the top of the screen.
vertical_pad
is anNumericProperty
and defaults to dp(68).
The name of the animation transition.
opening_transition
is anStringProperty
and defaults to ‘in_quad’.
Icon banner.
icon
is anStringProperty
and defaults to ‘data/logo/kivy-icon-128.png’.
The widget that is under the banner. It will be shifted down to the height of the banner.
over_widget
is anObjectProperty
and defaults to None.
List of lines for banner text. Must contain no more than three lines for a ‘one-line’, ‘two-line’ and ‘three-line’ banner, respectively.
text
is anListProperty
and defaults to [].
The action of banner.
To add one action, make a list [‘name_action’, callback] where ‘name_action’ is a string that corresponds to an action name and
callback
is the function called on a touch release event.left_action
is anListProperty
and defaults to [].
Works the same way as
left_action
.right_action
is anListProperty
and defaults to [].
Banner type. . Available options are: (“one-line”, “two-line”, “three-line”, “one-line-icon”, “two-line-icon”, “three-line-icon”).
type
is anOptionProperty
and defaults to ‘one-line’.