Counter#

Counter widget is a simple way to input a number using +/- buttons.

from aiogram_dialog.widgets.kbd import ManagedCounter, Counter


async def on_text_click(
        event: CallbackQuery,
        widget: ManagedCounter,
        dialog_manager: DialogManager,
) -> None:
    await event.answer(f"Value: {widget.get_value()}")


counter = Counter(
    id="someid",
    default=0,
    max_value=1000,
    on_text_click=on_text_click,
)

Classes#

class aiogram_dialog.widgets.kbd.counter.OnCounterEvent(*args, **kwargs)#
abstract async __call__(event, counter, dialog_manager)#

Call self as a function.

Parameters:
  • event (CallbackQuery | Message | DialogUpdateEvent | ChatMemberUpdated | ChatJoinRequest) –

  • counter (ManagedCounter) –

  • dialog_manager (DialogManager) –

class aiogram_dialog.widgets.kbd.Counter(id, plus=<aiogram_dialog.widgets.text.base.Const object>, minus=<aiogram_dialog.widgets.text.base.Const object>, text=<aiogram_dialog.widgets.text.format.Format object>, min_value=0, max_value=999999, increment=1, default=0, cycle=False, on_click=None, on_text_click=None, on_value_changed=None, when=None)#

Counter widget.

Used to represent number with increment/decrement buttons To remove any button set its text to None

Parameters:
  • id (str) –

  • plus (Text | None) –

  • minus (Text | None) –

  • text (Text | None) –

  • min_value (float) –

  • max_value (float) –

  • increment (float) –

  • default (float) –

  • cycle (bool) –

  • on_click (OnCounterEvent | WidgetEventProcessor | None) –

  • on_text_click (OnCounterEvent | WidgetEventProcessor | None) –

  • on_value_changed (OnCounterEvent | WidgetEventProcessor | None) –

  • when (str | MagicFilter | Predicate | None) –

__init__(id, plus=<aiogram_dialog.widgets.text.base.Const object>, minus=<aiogram_dialog.widgets.text.base.Const object>, text=<aiogram_dialog.widgets.text.format.Format object>, min_value=0, max_value=999999, increment=1, default=0, cycle=False, on_click=None, on_text_click=None, on_value_changed=None, when=None)#

Init counter widget.

Parameters:
  • id (str) – ID of widget

  • plus (Text | None) – Text to render +-button. Set None to disable

  • minus (Text | None) – Text to render --button. Set None to disable

  • text (Text | None) – Text to render button with current value. Set None to disable

  • min_value (float) – Minimal allowed value

  • max_value (float) – Maximum allowed value

  • increment (float) – Step used to increment

  • default (float) – Default value

  • cycle (bool) – Whether cycle values on overflow

  • on_click (OnCounterEvent | WidgetEventProcessor | None) – Callback to process any click

  • on_text_click (OnCounterEvent | WidgetEventProcessor | None) – Callback to process click on text-button

  • on_value_changed (OnCounterEvent | WidgetEventProcessor | None) – Callback to process value changes, regardless of the reason

  • when (str | MagicFilter | Predicate | None) – Condition when to show widget

Return type:

None

class aiogram_dialog.widgets.kbd.ManagedCounter(widget, manager)#
Parameters:
  • widget (W) –

  • manager (DialogManager) –

get_value()#

Get current value set in counter.

Return type:

float

async set_value(value)#

Change current counter value.

Parameters:

value (float) –

Return type:

None