3.3.3. Button

The Button control is used to start or confirm an operation in response to a click from users.

button_object.set_text(content, [color_r, color_g, color_b, color_a, ]align, size)
Description:

Set the text attribute of the button object

参数:
  • content (string) – The content of the string displayed on the button
  • [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_Button.set_text(120, 120, 120, 255, text_anchor.upper_left, 12)

Example description:
 

Set the rgb value of text color to (120, 120, 120), the transparency to 255, the text alignment mode to top-left, and the font size to 12

button_object.set_text_color(r, g, b, a)
Description:

Set the color of the 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_button.set_text_color(120, 120, 120, 200)

Example description:
 

Set the rgb value of text color to (120, 120, 120) and the transparency to 200

button_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_button.set_text_align(text_anchor.upper_left)
Example description:
 Set the text alignment mode to top-left
button_object.set_text_size(size)
Description:Set the text font size
参数:size (int) – Text font size
返回:None
Example:my_button.set_text_size(12)
Example description:
 Set the text font size to 12
button_object.set_background_color(r, g, b, a)
Description:

Set the background color of the button

参数:
  • r (int) – The r value of font color, whose range is [0, 255]
  • g (int) – The g value of font color, whose range is [0, 255]
  • b (int) – The b value of font color, whose range is [0, 255]
  • a (int) – The transparency of font color, whose range is [0, 255]
返回:

None

Example:

my_button.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