Skip to main content

Button

Examples​

Live demo

Basic buttons​

import pglet
from pglet import Button
with pglet.page("basic-buttons") as page:
page.add(
Button("Standard"),
Button("Standard disabled", disabled=True),
Button("Primary", primary=True),
Button("Primary disabled", primary=True, disabled=True))

Button with click event​

import pglet
from pglet import Button, Text

with pglet.page("button-with-click-event") as page:

def button_clicked(e):
b.data += 1
t.value = f"Button clicked {b.data} time(s)"
page.update()

b = Button("Button with 'click' event", on_click=button_clicked, title='Click me!', data=0)
t = Text()

page.add(b, t)

input()

Compound buttons​

import pglet
from pglet import Button
with pglet.page("compound-buttons") as page:
page.add(
Button("Compound", secondary_text='This is a secondary text', compound=True),
Button("Primary compound", secondary_text='This is a secondary text', compound=True, primary=True))

Buttons with icons​

import pglet
from pglet import Button
with pglet.page("buttons-with-icons") as page:
page.add(
Button("Create account", icon='AddFriend', primary=True),
Button("New item", icon='Add'),
Button("Delete", icon='Delete'))

Icon only buttons​

import pglet
from pglet import Button
with pglet.page("icon-only-buttons") as page:
page.add(
Button(icon='Emoji2', title='Emoji!'),
Button(icon='Calendar', title='Calendar!'))

Toolbar buttons​

import pglet
from pglet import Button, Stack
with pglet.page("toolbar-buttons") as page:
page.add(Stack(horizontal=True, controls=[
Button(text="New item", toolbar=True, icon='Add'),
Button(text="Send", toolbar=True, icon='Mail'),
Button(text="Show example", toolbar=True, icon='ChevronDown'),
Button(text="Delete", toolbar=True, icon_color='red', icon='Delete')
]))
import pglet
from pglet import Button
with pglet.page("link-buttons") as page:
page.add(
Button(action=True, icon='Globe', text='Pglet website',url='https://pglet.io', new_window=True),
Button(icon='MyMoviesTV', text='Go to Disney', url='https://disney.com', new_window=True))

Context menu buttons​

import pglet
from pglet import Button, Stack, button
with pglet.page("context-menu-buttons") as page:
page.add(Stack(horizontal=True, controls=[
Button(icon='Add', text='New item', menu_items=[
button.MenuItem(text='Email message', icon='Mail'),
button.MenuItem(text='Calendar event', icon='Calendar')
]),
Button(text='Button with sub-menus', menu_items=[
button.MenuItem(text='New', icon='Add', sub_menu_items=[
button.MenuItem(text='Email message', icon='Mail'),
button.MenuItem(text='Calendar event', icon='Calendar')
]),
button.MenuItem(text='Share', icon='Share', split=True, sub_menu_items=[
button.MenuItem(text='Share to Twitter'),
button.MenuItem(text='Share to Facebook'),
button.MenuItem('Share to Somewhere'),
button.MenuItem('Share to email', sub_menu_items=[
button.MenuItem('Share to Outlook'),
button.MenuItem('Share to Gmail')
])
]),
button.MenuItem(divider=True),
button.MenuItem(text='To Pglet', icon='Globe', icon_color='green', url='https://pglet.io', new_window=True, secondary_text='New Window')
]),
]))

Split buttons​

import pglet
from pglet import Button, Stack, button
with pglet.page("split-buttons") as page:
page.add(Stack(horizontal=True, controls=[
Button(split=True, text='Standard', menu_items=[
button.MenuItem('Email message', icon='Mail'),
button.MenuItem('Calendar event', icon='Calendar')
]),
Button(split=True, primary=True, text='Primary', menu_items=[
button.MenuItem('Email message', icon='Mail'),
button.MenuItem('Calendar event', icon='Calendar')
])
]))

Action buttons​

import pglet
from pglet import Button, Stack
with pglet.page("action-button") as page:
page.add(Stack(horizontal=True, controls=[
Button(action=True, icon='AddFriend', text='Create account')
]))

Properties​

NameTypeDefaultDescription
primaryboolfalseThe button with a theme color background. Usually, there is only one primary button on a form.
compoundboolfalseRender compound button with primary and secondaryText on a second line.
actionboolfalseRender button as a link without a border.
toolbarboolfalseRender toolbar-like button.
splitboolfalseIf set to true, and if menu items are provided, the button will render as a SplitButton.
focusedboolfalseWhen set to true the focus is set on the control when it's shown on the page or page opened.
textstringThe text displayed on a button.
secondaryTextstringDescription of the action this button takes. Only used for compound buttons.
urlstringIf provided, the button will be rendered as a link.
newWindowboolfalseWhether to open link in a new browser window.
titlestringPopup hint for the button.
iconstringIcon shown in the button.
iconColorstringIcon color.
datastringAdditional data attached to the control. The value is passed in click event data.

Events​

NameDescription
clickFires when a user clicks the button.
focusFires when the control has received focus.
blurFires when the control has lost focus.

Child controls​

Item control​

Represents a menu item within a context menu button.

Properties​

NameTypeDefaultDescription
textstringText of the menu item. If a standard hyphen (-) is passed in, then the item will be rendered as a divider. If a dash must appear as text, use an emdash (—), figuredash (‒), or minus symbol (−) instead.
secondaryTextstringSeconday description for the menu item to display.
urlstringURL to navigate to for this menu item.
newWindowboolfalseWhether to open link in a new browser window.
iconstringAn optional icon to display next to the item.
iconColorstringIcon color.
iconOnlyboolfalseShow only an icon for this item, not text. Does not apply if item is in the overflow.
splitboolfalseWhether or not this menu item is a SplitButton.
dividerboolfalseDisplay menu item as a divider.

Events​

NameDescription
clickFires when menu item is invoked.

Child controls​

Item control can contain other item controls to add nested menu items.