26
26
@control ("IconButton" )
27
27
class IconButton (ConstrainedControl , AdaptiveControl ):
28
28
"""
29
- An icon button is a round button with an icon in the middle that reacts to touches by filling with color (ink).
29
+ An icon button is a round button with an icon in the middle that reacts to touches
30
+ by filling with color (ink).
30
31
31
- Icon buttons are commonly used in the toolbars, but they can be used in many other places as well.
32
+ Icon buttons are commonly used in the toolbars, but they can be used in many other
33
+ places as well.
32
34
33
35
Online docs: https://flet.dev/docs/controls/iconbutton
34
36
"""
@@ -44,35 +46,205 @@ def __setattr__(self, name, value):
44
46
super ().__setattr__ (name , value )
45
47
46
48
icon : Optional [IconValueOrControl ] = None
49
+ """
50
+ Icon shown in the button.
51
+ """
52
+
47
53
icon_color : OptionalColorValue = None
54
+ """
55
+ Icon [color](https://flet.dev/docs/reference/colors).
56
+ """
57
+
48
58
icon_size : OptionalNumber = None
49
- selected : bool = False
59
+ """
60
+ Icon size in virtual pixels.
61
+
62
+ Defaults to `24`.
63
+ """
64
+
65
+ selected : Optional [bool ] = None
66
+ """
67
+ The optional selection state of the icon button.
68
+
69
+ If this property is not set, the button will behave as a normal push button,
70
+ otherwise, the button will toggle between showing `icon` and `selected_icon` based
71
+ on the value of `selected`.
72
+
73
+ If True, it will show `selected_icon`, if False it will show `icon`.
74
+ """
75
+
50
76
selected_icon : Optional [IconValueOrControl ] = None
77
+ """
78
+ Icon shown in the button in selected state.
79
+ """
80
+
51
81
selected_icon_color : OptionalColorValue = None
82
+ """
83
+ Icon [color](https://flet.dev/docs/reference/colors) for the selected state.
84
+
85
+ An example of icon toggle button:
86
+
87
+ <img src="/img/blog/gradients/toggle-icon-button.gif" className="screenshot-10" />
88
+
89
+ ```python
90
+ import flet as ft
91
+
92
+ def main(page: ft.Page):
93
+
94
+ def toggle_icon_button(e):
95
+ e.control.selected = not e.control.selected
96
+
97
+ page.add(
98
+ ft.IconButton(
99
+ icon=ft.Icons.BATTERY_1_BAR,
100
+ selected_icon=ft.Icons.BATTERY_FULL,
101
+ on_click=toggle_icon_button,
102
+ selected=False,
103
+ style=ft.ButtonStyle(
104
+ color={"selected": ft.Colors.GREEN, "": ft.Colors.RED},
105
+ ),
106
+ )
107
+ )
108
+
109
+ ft.app(main)
110
+ ```
111
+ """
112
+
52
113
bgcolor : OptionalColorValue = None
114
+ """
115
+ TBD
116
+ """
117
+
53
118
highlight_color : OptionalColorValue = None
119
+ """
120
+ The button's [color](https://flet.dev/docs/reference/colors) when the button is
121
+ pressed. The highlight fades in quickly as the button is held down.
122
+ """
123
+
54
124
style : Optional [ButtonStyle ] = None
125
+ """
126
+ Value is of type [`ButtonStyle`](https://flet.dev/docs/reference/types/buttonstyle).
127
+ """
128
+
55
129
autofocus : bool = False
130
+ """
131
+ True if the control will be selected as the initial focus. If there is more than
132
+ one control on a page with autofocus set, then the first one added to the page will
133
+ get focus.
134
+ """
135
+
56
136
disabled_color : OptionalColorValue = None
137
+ """
138
+ The [color](https://flet.dev/docs/reference/colors) to use for the icon inside the
139
+ button when disabled.
140
+ """
141
+
57
142
hover_color : OptionalColorValue = None
143
+ """
144
+ The button's [color](https://flet.dev/docs/reference/colors) when hovered.
145
+ """
146
+
58
147
focus_color : OptionalColorValue = None
148
+ """
149
+ The button's [color](https://flet.dev/docs/reference/colors) when in focus.
150
+ """
151
+
59
152
splash_color : OptionalColorValue = None
153
+ """
154
+ The primary [color](https://flet.dev/docs/reference/colors) of the button when the
155
+ button is in the down (pressed) state.
156
+ """
157
+
60
158
splash_radius : OptionalNumber = None
159
+ """
160
+ The splash radius. Honoured only when in Material 2.
161
+ """
162
+
61
163
alignment : Optional [Alignment ] = None
164
+ """
165
+ Defines how the icon is positioned within the IconButton. Alignment is an instance
166
+ of [`Alignment`](https://flet.dev/docs/reference/types/alignment) class.
167
+
168
+ Defaults to `alignment.center`.
169
+ """
170
+
62
171
padding : OptionalPaddingValue = None
63
- enable_feedback : Optional [bool ] = True
172
+ """
173
+ Defines the padding around this button. The entire padded icon will react to input
174
+ gestures.
175
+
176
+ Value is of type [`Padding`](https://flet.dev/docs/reference/types/padding) and
177
+ defaults to `Padding.all(8)`.
178
+ """
179
+
180
+ enable_feedback : Optional [bool ] = None
181
+ """
182
+ Whether detected gestures should provide acoustic and/or haptic feedback.
183
+ On Android, for example, setting this to `True` produce a click sound and a
184
+ long-press will produce a short vibration.
185
+ """
186
+
64
187
url : Optional [str ] = None
188
+ """
189
+ The URL to open when the button is clicked. If registered, `on_click` event is fired
190
+ after that.
191
+ """
192
+
65
193
url_target : Optional [UrlTarget ] = None
194
+ """
195
+ Where to open URL in the web mode.
196
+
197
+ Value is of type [`UrlTarget`](https://flet.dev/docs/reference/types/urltarget).
198
+ """
199
+
66
200
mouse_cursor : Optional [MouseCursor ] = None
201
+ """
202
+ The cursor to be displayed when a mouse pointer enters or is hovering over this
203
+ control.
204
+
205
+ Value is of type [`MouseCursor`](https://flet.dev/docs/reference/types/mousecursor).
206
+ """
207
+
67
208
visual_density : Optional [VisualDensity ] = None
209
+ """
210
+ Defines how compact the control's layout will be.
211
+
212
+ Value is of type [`VisualDensity`](https://flet.dev/docs/reference/types/visualdensity).
213
+ """
214
+
68
215
size_constraints : Optional [BoxConstraints ] = None
216
+ """
217
+ TBD
218
+ """
219
+
69
220
on_click : OptionalControlEventCallable = None
221
+ """
222
+ Fires when a user clicks the button.
223
+ """
224
+
70
225
on_focus : OptionalControlEventCallable = None
226
+ """
227
+ Fires when the control has received focus.
228
+ """
229
+
71
230
on_blur : OptionalControlEventCallable = None
231
+ """
232
+ Fires when the control has lost focus.
233
+ """
234
+
72
235
content : Optional [Control ] = None # todo(0.70.3): remove in favor of icon
236
+ """
237
+ A Control representing custom button content.
238
+ """
73
239
74
240
async def focus_async (self ):
241
+ """
242
+ Moves focus to a button.
243
+ """
75
244
await self ._invoke_method_async ("focus" )
76
245
77
246
def focus (self ):
247
+ """
248
+ Moves focus to a button.
249
+ """
78
250
asyncio .create_task (self .focus_async ())
0 commit comments