@@ -4,23 +4,23 @@ Adding widgets
4
4
==============
5
5
6
6
For adding new widgets to the Menu you can create new instances of the respective
7
- widget class. Or you can use the :py:class: `pygame_menu._widgetmanager.WidgetManager ` class stored in ``Menu.add ``
8
- property. These methods configure the widget and add to the Menu in a simple way.
7
+ widget class. Or you can use the :py:class: `pygame_menu._widgetmanager.WidgetManager `
8
+ class stored in ``Menu.add `` property. These methods configure the widget and add
9
+ to the Menu in a simple way.
9
10
10
11
11
12
Add a button
12
13
------------
13
14
14
- A button is a text that fire action when the user trigger it. An action
15
- is linked to a button by defining the `action ` parameter with one of the
16
- three values:
15
+ A button is a text that fire action when the user trigger it. An action is linked
16
+ to a button by defining the `action ` parameter with one of the three values:
17
17
18
18
- an other :py:class: `pygame_menu.menu.Menu `, in this case, it will be displayed
19
19
when the button is triggered.
20
- - a python callable object (a function, a method, a class, ...)
21
- that will be called with the given arguments.
22
- - a specific event of :py:mod: `pygame_menu `. The possible events are
23
- the following:
20
+ - a python callable object (a function, a method, a class, ...) that will be
21
+ called with the given arguments.
22
+ - a specific event of :py:mod: `pygame_menu `. The possible events are the
23
+ following:
24
24
25
25
========================================== =====================================
26
26
Event Description
@@ -43,13 +43,13 @@ three values:
43
43
about_menu = pygame_menu.Menu(... )
44
44
45
45
def func (name ):
46
- print (' Hello world from' , name) # name will be 'foo'
46
+ print (' Hello world from' , name) # Name will be 'foo'
47
47
48
- menu.add.button(' Exec' , func, ' foo' , # Execute a function
48
+ menu.add.button(' Exec' , func, ' foo' , # Execute a function
49
49
align = pygame_menu.locals.ALIGN_LEFT )
50
- menu.add.button(about_menu.get_title(), about_menu, # Open a sub-menu
50
+ menu.add.button(about_menu.get_title(), about_menu, # Open a sub-menu
51
51
shadow = True , shadow_color = (0 , 0 , 100 ))
52
- menu.add.button(' Exit' , pygame_menu.events.EXIT , # Link to exit action
52
+ menu.add.button(' Exit' , pygame_menu.events.EXIT , # Link to exit action
53
53
align = pygame_menu.locals.ALIGN_RIGHT )
54
54
55
55
.. automethod :: pygame_menu._widgetmanager.WidgetManager.button
@@ -58,10 +58,9 @@ three values:
58
58
Add a choices list (selector)
59
59
-----------------------------
60
60
61
- A selector gives the possibility choose a value in a predefined list.
62
- An item of a selector is a tuple: the first element is the text
63
- displayed, the others are the arguments passed to the callbacks
64
- ``onchange `` and ``onreturn ``.
61
+ A selector gives the possibility choose a value in a predefined list. An item of
62
+ a selector is a tuple: the first element is the text displayed, the others are
63
+ the arguments passed to the callbacks ``onchange `` and ``onreturn ``.
65
64
66
65
**Example: **
67
66
@@ -83,16 +82,16 @@ displayed, the others are the arguments passed to the callbacks
83
82
widget.get_selection_effect().color = color
84
83
85
84
items = [(' Default' , (255 , 255 , 255 )),
86
- (' Black' , (0 , 0 , 0 )),
87
- (' Blue' , (0 , 0 , 255 )),
88
- (' Random' , (- 1 , - 1 , - 1 ))]
85
+ (' Black' , (0 , 0 , 0 )),
86
+ (' Blue' , (0 , 0 , 255 )),
87
+ (' Random' , (- 1 , - 1 , - 1 ))]
89
88
selector = menu.add.selector(
90
- title = ' Current color: ' ,
91
- items = ,
92
- onreturn = change_background_color, # user press "Return" button
89
+ title = ' Current color:\t ' ,
90
+ items = items ,
91
+ onreturn = change_background_color, # User press "Return" button
93
92
onchange = change_background_color # User changes value with left/right keys
94
93
)
95
- selector.add_self_to_kwargs() # callbacks will receive widget as parameter
94
+ selector.add_self_to_kwargs() # Callbacks will receive widget as parameter
96
95
selector2 = menu.add.selector(
97
96
title = ' New color:' ,
98
97
items = items,
@@ -126,10 +125,9 @@ that retrieves the clock/date string from ``time.strftime``.
126
125
Add a color entry
127
126
-----------------
128
127
129
- A color input is similar as a text input but with a limited choice of
130
- characters to enter a RGB value of HEX decimal one. There is also a
131
- area to show the current color. By default the RGB integers separator
132
- is a comma (``, ``).
128
+ A color input is similar as a text input but with a limited choice of characters
129
+ to enter a RGB value of HEX decimal one. There is also a area to show the current
130
+ color. By default the RGB integers separator is a comma (``, ``).
133
131
134
132
**Example: **
135
133
@@ -144,11 +142,14 @@ is a comma (``,``).
144
142
def check_color (value ):
145
143
print (' New color:' , value)
146
144
147
- menu.add.color_input(' RGB color 1: ' , color_type = pygame_menu.widgets.COLORINPUT_TYPE_RGB ,
145
+ menu.add.color_input(' RGB color 1: ' ,
146
+ color_type = pygame_menu.widgets.COLORINPUT_TYPE_RGB ,
148
147
default = (255 , 0 , 255 ), font_size = 18 )
149
- menu.add.color_input(' RGB color 2: ' , color_type = pygame_menu.widgets.COLORINPUT_TYPE_RGB ,
148
+ menu.add.color_input(' RGB color 2: ' ,
149
+ color_type = pygame_menu.widgets.COLORINPUT_TYPE_RGB ,
150
150
input_separator = ' -' , font_size = 18 )
151
- menu.add.color_input(' HEX color 3: ' , color_type = pygame_menu.widgets.COLORINPUT_TYPE_HEX ,
151
+ menu.add.color_input(' HEX color 3: ' ,
152
+ color_type = pygame_menu.widgets.COLORINPUT_TYPE_HEX ,
152
153
default = ' #ffaa11' , font_size = 18 )
153
154
154
155
.. automethod :: pygame_menu._widgetmanager.WidgetManager.color_input
@@ -157,10 +158,9 @@ is a comma (``,``).
157
158
Add a drop selection
158
159
--------------------
159
160
160
- A drop selector gives the possibility choose a value in a predefined list.
161
- An item of a drop selector is a tuple: the first element is the text
162
- displayed, the others are the arguments passed to the callbacks
163
- ``onchange `` and ``onreturn ``.
161
+ A drop selector gives the possibility choose a value in a predefined list. An item
162
+ of a drop selector is a tuple: the first element is the text displayed, the others
163
+ are the arguments passed to the callbacks ``onchange `` and ``onreturn ``.
164
164
165
165
**Example: **
166
166
@@ -182,7 +182,7 @@ displayed, the others are the arguments passed to the callbacks
182
182
selector_sum = menu.add.dropselect(
183
183
title = ' What is the value of π?' ,
184
184
items = [(' 3 (Engineer)' , 0 ),
185
- (' 3.141592653589793238462643383279502884197169399375105820974944592 ' , 1 ),
185
+ (' 3.1415926535897932384626433832795028841971693993751058209 ' , 1 ),
186
186
(' 4' , 2 ),
187
187
(' I don\' t know what is π' , 3 )],
188
188
font_size = 16 ,
@@ -221,9 +221,8 @@ Add a drop selection multiple
221
221
-----------------------------
222
222
223
223
A multiple drop selector gives the possibility choose a value in a predefined list.
224
- An item of a drop selector is a tuple: the first element is the text
225
- displayed, the others are the arguments passed to the callbacks
226
- ``onchange `` and ``onreturn ``.
224
+ An item of a drop selector is a tuple: the first element is the text displayed,
225
+ the others are the arguments passed to the callbacks ``onchange `` and ``onreturn ``.
227
226
228
227
**Example: **
229
228
@@ -256,9 +255,9 @@ displayed, the others are the arguments passed to the callbacks
256
255
Add a frame
257
256
-----------
258
257
259
- Frame is a widget container, it can pack many widgets both horizontally
260
- or vertically. All widgets within a same Frame count as one widget position,
261
- so using Frames is useful when designing column/row layout. Frames can contain
258
+ Frame is a widget container, it can pack many widgets both horizontally or
259
+ vertically. All widgets within a same Frame count as one widget position, so
260
+ using Frames is useful when designing column/row layout. Frames can contain
262
261
widgets or even more frames.
263
262
264
263
There is two types of frames, horizontal (h) and vertical (v) ones. These change
@@ -282,18 +281,24 @@ the way the widgets are added to the frame (packed).
282
281
283
282
frame_title.pack(menu.add.label(' Settings' , padding = 0 ), margin = (2 , 2 ))
284
283
frame_title.pack(
285
- menu.add.button(' Close' , pygame_menu.events.EXIT , padding = (0 , 5 ), background_color = (100 , 100 , 100 )),
284
+ menu.add.button(' Close' , pygame_menu.events.EXIT , padding = (0 , 5 ),
285
+ background_color = (100 , 100 , 100 )),
286
286
align = pygame_menu.locals.ALIGN_RIGHT , margin = (2 , 2 ))
287
- frame_content.pack(menu.add.label(' Pick a number' , font_color = (150 , 150 , 150 )),
288
- align = pygame_menu.locals.ALIGN_CENTER )
287
+ frame_content.pack(
288
+ menu.add.label(' Pick a number' , font_color = (150 , 150 , 150 )),
289
+ align = pygame_menu.locals.ALIGN_CENTER )
289
290
frame_numbers = menu.add.frame_h(250 , 41 , padding = 0 )
290
291
frame_content.pack(frame_numbers)
291
292
for i in range (9 ):
292
- frame_numbers.pack(menu.add.button(i, font_color = (5 * i, 11 * i, 13 * i), padding = (0 , 5 ), font_size = 30 ),
293
- align = pygame_menu.locals.ALIGN_CENTER )
293
+ frame_numbers.pack(
294
+ menu.add.button(i, font_color = (5 * i, 11 * i, 13 * i),
295
+ padding = (0 , 5 ), font_size = 30 ),
296
+ align = pygame_menu.locals.ALIGN_CENTER )
294
297
frame_content.pack(menu.add.vertical_margin(15 ))
295
- frame_content.pack(menu.add.toggle_switch(' Nice toggle' , False , width = 100 , font_color = (150 , 150 , 150 ), padding = 0 ),
296
- align = pygame_menu.locals.ALIGN_CENTER )
298
+ frame_content.pack(
299
+ menu.add.toggle_switch(' Nice toggle' , False , width = 100 ,
300
+ font_color = (150 , 150 , 150 ), padding = 0 ),
301
+ align = pygame_menu.locals.ALIGN_CENTER )
297
302
298
303
**Example: **
299
304
@@ -305,7 +310,8 @@ the way the widgets are added to the frame (packed).
305
310
306
311
menu = pygame_menu.Menu(... )
307
312
308
- frame = menu.add.frame_v(400 , 800 , background_color = (50 , 50 , 50 ), padding = 0 , max_width = 300 , max_height = 100 )
313
+ frame = menu.add.frame_v(400 , 800 , background_color = (50 , 50 , 50 ), padding = 0 ,
314
+ max_width = 300 , max_height = 100 )
309
315
frame.set_title(' My Frame App' , title_font_color = ' white' , padding_inner = (2 , 5 ))
310
316
311
317
frame.pack(menu.add.dropselect(
@@ -354,8 +360,8 @@ configured before the addition.
354
360
Add a label
355
361
-----------
356
362
357
- A label is used to display a text. If the text is too large, it
358
- can be wrapped in order to fit the menu size.
363
+ A label is used to display a text. If the text is too large, it can be wrapped in
364
+ order to fit the menu size.
359
365
360
366
**Example: **
361
367
@@ -367,10 +373,10 @@ can be wrapped in order to fit the menu size.
367
373
368
374
menu = pygame_menu.Menu(... )
369
375
370
- HELP = " Press ESC to enable/disable Menu " \
371
- " Press ENTER to access a Sub-Menu or use an option " \
372
- " Press UP/DOWN to move through Menu " \
373
- " Press LEFT/RIGHT to move through Selectors."
376
+ HELP = ' Press ESC to enable/disable Menu ' \
377
+ ' Press ENTER to access a Sub-Menu or use an option ' \
378
+ ' Press UP/DOWN to move through Menu ' \
379
+ ' Press LEFT/RIGHT to move through Selectors.'
374
380
menu.add.label(HELP , max_char = - 1 , font_size = 20 )
375
381
376
382
.. automethod :: pygame_menu._widgetmanager.WidgetManager.label
@@ -379,8 +385,8 @@ can be wrapped in order to fit the menu size.
379
385
Add a none widget
380
386
-----------------
381
387
382
- A none widget is used to fill column/row layout, store information
383
- or even add drawing callbacks for being executed on each menu draw.
388
+ A none widget is used to fill column/row layout, store information or even add
389
+ drawing callbacks for being executed on each menu draw.
384
390
385
391
.. code-block :: python
386
392
@@ -394,8 +400,8 @@ or even add drawing callbacks for being executed on each menu draw.
394
400
Add a surface
395
401
-------------
396
402
397
- A surface widget only accepts an external surface which is drawn on the Menu.
398
- The widget size is the same as the surface, considering also the margin and the padding.
403
+ A surface widget only accepts an external surface which is drawn on the Menu. The
404
+ widget size is the same as the surface, considering also the margin and the padding.
399
405
400
406
**Example: **
401
407
@@ -420,10 +426,9 @@ The widget size is the same as the surface, considering also the margin and the
420
426
Add a table
421
427
-----------
422
428
423
- A table is a frame which packs widgets in a structured way. Tables
424
- can contain a text, numbers, or even more widgets (Frames, Tables, Images, etc).
425
- All widgets are read-only, them do not accept any event, only scrollable frames
426
- work.
429
+ A table is a frame which packs widgets in a structured way. Tables can contain a
430
+ text, numbers, or even more widgets (Frames, Tables, Images, etc). All widgets are
431
+ read-only, them do not accept any event, only scrollable frames work.
427
432
428
433
**Example: **
429
434
@@ -485,9 +490,9 @@ and a widget (Image):
485
490
Add a text entry
486
491
----------------
487
492
488
- A text input permits to enter a string using a keyboard. Restriction
489
- on entered characters can be set using ``input_type ``, ``maxchar ``,
490
- ``maxwidth `` and `` valid_chars `` parameters.
493
+ A text input permits to enter a string using a keyboard. Restriction on entered
494
+ characters can be set using ``input_type ``, ``maxchar ``, `` maxwidth `` and
495
+ ``valid_chars `` parameters.
491
496
492
497
**Example: **
493
498
@@ -512,8 +517,8 @@ on entered characters can be set using ``input_type``, ``maxchar``,
512
517
Add a toggle switch
513
518
-------------------
514
519
515
- A fully customizable switch between two states (``On ``, ``Off ``). If
516
- you need more options, take a look at the ``ToggleSwitch `` widget class.
520
+ A fully customizable switch between two states (``On ``, ``Off ``). If you need
521
+ more options, take a look at the ``ToggleSwitch `` widget class.
517
522
518
523
**Example: **
519
524
@@ -535,8 +540,8 @@ you need more options, take a look at the ``ToggleSwitch`` widget class.
535
540
Add a vertical spacer
536
541
---------------------
537
542
538
- A vertical spacer can be added between two widgets to have a better
539
- visual rendering of the menu.
543
+ A vertical spacer can be added between two widgets to have a better visual
544
+ rendering of the menu.
540
545
541
546
**Example: **
542
547
@@ -580,10 +585,9 @@ Adds a clickable url link.
580
585
Add an image
581
586
------------
582
587
583
- An image can be displayed on a menu.
584
- The ``scale `` parameter represent the scaling ratio of the image width
585
- and height. When ``scale_smooth=True ``, the rendering is better but it
586
- requires more CPU resources.
588
+ An image can be displayed on a menu. The ``scale `` parameter represent the
589
+ scaling ratio of the image width and height. When ``scale_smooth=True ``, the
590
+ rendering is better but it requires more CPU resources.
587
591
588
592
**Example: **
589
593
0 commit comments