NoneWidget¶
Bases:
pygame_menu.widgets.core.widget.Widget
None widget. Useful if used for filling column/row layout. None widget don’t accept padding, margin, cannot be selected or updated.
Note
This widget does not implement any transformation.
- Parameters
widget_id (
str
) – ID of the widget
Adds a function to the Widget to be executed each time the widget is drawn.
The function that this method receives receives two objects: the Widget itself and the Menu reference.
import math def draw_update_function(widget, menu): t = widget.get_attribute('t', 0) t += menu.get_clock().get_time() widget.set_padding(10*(1 + math.sin(t)))) # Oscillating padding button = menu.add.button('This button updates its padding', None) button.set_draw_callback(draw_update_function)
After creating a new callback, this functions returns the ID of the call. It can be removed anytime using
pygame_menu.widgets.core.widget.Widget.remove_draw_callback()
.Note
If Menu surface cache is enabled this method may run only once. To force running the added method each time call
widget.force_menu_surface_update()
to force Menu update the cache status if the drawing callback does not make the Widget to render. Remember that rendering the Widget forces the Menu to update its surface, thus updating the cache too.
Adds the Widget object to kwargs, it helps to get the Widget reference for callbacks. It raises
KeyError
if key is duplicated.
Apply callbacks on Widget draw.
- Return type
- Returns
Self reference
Draw the Widget on a given surface.
Note
Widget drawing order:
Background color
prev
decoratorWidget selection effect (if prev)
Widget surface
Widget selection effect (if post)
Widget border
post
decorator
Draw Widget if selected after all widgets have been drawn. This method should also update
last_surface
; seepygame_menu.widgets.DropSelect
widget example.
Forces menu surface cache to update after next drawing call. This also updates widget decoration.
Note
This method only updates the surface cache, without forcing re-rendering of all Menu widgets as
pygame_menu.widgets.core.widget.Widget.force_menu_surface_update()
does.- Return type
- Returns
Self reference
Forces menu surface update after next rendering call. This method automatically updates widget decoration cache as Menu render forces it to re-render.
Note
This method is expensive, as menu surface update forces re-rendering of all widgets (because them can change in size, position, etc…).
- Return type
- Returns
Self reference
Return the Widget alignment.
- Return type
- Returns
Widget align
Get an attribute value.
Return the widget border properties.
Return the Class+ID as a string.
- Return type
- Returns
Class+ID format
Get the Widget column/row position.
Get counter attribute.
Return the Widget decorator API.
- Return type
- Returns
Decorator API
Return rect to be used in Widget focus.
- Return type
- Returns
Focus rect
Get container frame of Widget. If Widget is not within a Frame, the method returns
None
.- Returns
Frame object
- Return type
Get frame depth (If frame is packed within another frame).
- Return type
- Returns
Frame depth
Return the Widget height.
Warning
If the widget is not rendered, this method will return
0
.
Return the object ID.
- Return type
- Returns
Object ID
Return the Menu reference,
None
if it has not been set.
Return the widget position tuple on x-axis and y-axis (x, y) in px.
- Parameters
apply_padding (
bool
) – Apply widget padding to positionuse_transformed_padding (
bool
) – Use scaled padding if the widget is scaledto_real_position (
bool
) – Get the real position within window (not the surface container)to_absolute_position (
bool
) – Get the absolute position within surface container, considering also the parent scrollarea positioningreal_position_visible (
bool
) – Return only the visible width/height ifto_real_position=True
- Return type
- Returns
Widget position
Return the scrollarea object.
- Return type
- Returns
ScrollArea object
Return the Widget size.
Warning
If the widget is not rendered this method might return
(0, 0)
.
Get Widget translate on x-axis and y-axis (x, y) in px.
Return the Widget width.
Warning
If the Widget is not rendered, this method will return
0
.
Return
True
if the object has the given attribute.
Hides the Widget.
- Return type
- Returns
Self reference
Return
True
if the Widget is floating.- Return type
- Returns
Float status
Return
True
if the Widget is visible.
Function executed if the Widget is removed from the Menu.
- Return type
- Returns
Self reference
Removes the given attribute from the object. Throws
IndexError
if the given key does not exist.- Parameters
key (
str
) – Key of the attribute- Return type
Base
- Returns
Self reference
Removes draw callback from ID.
Public rendering method.
Note
Unlike private
_render
method, public method forces widget rendering (callingpygame_menu.widgets.core.widget.Widget._force_render()
). Use this method only if the widget has changed the state. Running this function many times may affect the performance.Note
Before rendering, check out if the widget font/title/values are set. If not, it is probable that a zero-size surface is set.
Scroll to widget.
Set an attribute.
Set the (column, row, index) position. If the column or row is
-1
then the widget is not assigned to a certain column/row (for example, if it’s hidden).
Set the floating status. If
True
the Widget don’t contributes the width/height to the Menu widget positioning computation (for example, the surface area or the column/row layout), and don’t add one unit to the rows (use the same vertical place as the previous widget.For example, before floating:
---------------------------- | wid1 | wid3 | | wid2 | wid4 | ----------------------------
After
wid3.set_float(True)
:---------------------------- | wid1 | wid4 | | wid2,wid3 | | ----------------------------
If the Widget is within a Frame, it does not contribute to the width/height of the layout. Also, it is been set to the (0, 0) position, thus, the only way to move the Widget to a desired position is by translating it.
- Parameters
- Return type
- Returns
None
Set the Widget font shadow.
Note
See
pygame_menu.locals
for validposition
values.- Parameters
enabled – Shadow is enabled or not
color – Shadow color
position – Shadow position
offset – Shadow offset
- Return type
NoneWidget
- Returns
Self reference
Set Widget frame.
- Parameters
frame (
Frame
) – Frame object- Return type
- Returns
Self reference
Set the Widget menu reference.
Set the Widget position relative to its frame.
Set scrollarea reference. Mostly used for events.
- Parameters
scrollarea (
Optional
[ScrollArea
]) – Scrollarea object- Return type
- Returns
None
Set widget tab size.
- Parameters
tab_size – Width of a tab character
- Return type
NoneWidget
- Returns
Self reference
Set the Widget visible.
- Return type
- Returns
Self reference