3.3.4. Toggle¶
The Toggle control is used to draw a switch on the screen and perform certain operations by turning the switch on and off.
-
toggle_object.
set_text
(string, [color_r, color_g, color_b, color_a, ]align, size)¶ Description: Set the display text of the control
参数: - string (string) – The content of the string displayed on the control
- [color_r, color_g, color_b, color_a] (list) – Optional parameters, which indicate the color of the string to be displayed. These parameters respectively indicate the r value, b value, g value, and transparency of the displayed color, and their value ranges are all [0, 255].
- align (enum) – An optional enumeration-type parameter, which indicates the alignment mode of the text to be displayed. For details, see the
align
table. - size (int) – The font size of the displayed text
返回: None
Example: my_Toggle.set_text(120, 120, 120, 200, text_anchor.upper_left, 12)
Example description: Set the rgb value of text to (120, 120, 120), the transparency to 200, the text alignment mode to top-left, and the font size to 12
-
toggle_object.
set_text_color
(r, g, b, a)¶ Description: Sets the color of text
参数: - r (int) – The r value of text color, whose range is [0, 255]
- g (int) – The g value of text color, whose range is [0, 255]
- b (int) – The b value of text color, whose range is [0, 255]
- a (int) – The transparency of text color, whose range is [0, 255]
返回: None
Example: my_Toggle.set_text_color(120, 120, 120, 200)
Example description: Set the rgb value of the font to (120, 120, 120) and the transparency to 200
-
toggle_object.
set_text_align
(align)¶ Description: Set the text alignment mode 参数: align (enum) – An optional enumeration-type parameter, which indicates the alignment mode of the text to be displayed. For details, see the align
table.返回: None Example: my_Toggle.set_text_align(text_anchor.upper_left)
Example description: Set the font alignment mode to top-left
-
toggle_object.
set_text_size
(size)¶ Description: Set the text font size 参数: size (int) – Font size of text 返回: None Example: my_Toggle.set_text_size(12)
Example description: Set the font size of text to 12
-
toggle_object.
set_background_color
(r, g, b, a)¶ Description: Sets the background color of the control
参数: - r (int) – The r value of background color, whose range is [0, 255]
- g (int) – The g value of background color, whose range is [0, 255]
- b (int) – The b value of background color, whose range is [0, 255]
- a (int) – The transparency of background color, whose range is [0, 255]
返回: None
Example: my_Toggle.set_background_color(200, 200, 200, 230)
Example description: Set the rgb value of background color to (200, 200, 200) and the transparency to 230
-
toggle_object.
set_checkmark_color
(r, g, b, a)¶ Description: Set the color of the selection icon in the control
参数: - r (int) – The r value of icon color, whose range is [0, 255]
- g (int) – The g value of icon color, whose range is [0, 255]
- b (int) – The b value of icon color, whose range is [0, 255]
- a (int) – The transparency of icon color, whose range is [0, 255]
返回: None
Example: my_Toggle.set_checkmark_color(200, 200, 200, 230)
Example description: Set the rgb value of the selection icon to (200, 200, 200) and the transparency to 230
-
toggle_object.
set_is_on
(status)¶ Description: Set the state of the control 参数: status (bool) – Set whether the control is enabled, where True indicates yes, and False indicates no 返回: None Example: my_Toggle.set_is_on(True)
Example description: Set the Toggle control to enabled