Button
Button Element - Defines all possible buttons. The shortcuts such as Submit, FileBrowse, ... each create a Button
Button(
button_text = "",
button_type = 7,
target = (None, None),
tooltip = None,
file_types = (('ALL Files', '*'),),
initial_folder = None,
disabled = False,
change_submits = False,
enable_events = False,
image_filename = None,
image_data = None,
image_size = (None, None),
image_subsample = None,
border_width = None,
size = (None, None),
auto_size_button = None,
button_color = None,
font = None,
bind_return_key = False,
focus = False,
pad = None,
key = None,
k = None,
visible = True,
size_px = (None, None),
metadata = None
)
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
auto_size_button | bool | None | if True the button size is sized to fit the text |
bind_return_key | bool | False | If True the return key will cause this button to be pressed |
border_width | int | None | width of border around button in pixels |
button_color | (str, str) or str or (int, int) or None | None | Color of button. default is from theme or the window. Easy to remember which is which if you say "ON" between colors. "red" on "green". Normally a tuple, but can be a simplified-button-color-string "foreground on background". Can be a single color if want to set only the background. |
button_text | str | Text to be displayed on the button | |
button_type | int | 7 | You should NOT be setting this directly. ONLY the shortcut functions set this |
change_submits | bool | False | DO NOT USE. Only listed for backwards compat - Use enable_events instead |
disabled | (bool or str) | False | If True button will be created disabled. If BUTTON_DISABLED_MEANS_IGNORE then the button will be ignored rather than disabled using tkinter |
enable_events | bool | False | Turns on the element specific events. If this button is a target, should it generate an event when filled in |
file_types | Tuple[(str, str), ...] | (('ALL Files', '*'),) | the filetypes that will be used to match files. To indicate all files: (("ALL Files", ". *"),). |
focus | bool | False | if True, initial focus will be put on this button |
font | (str or (str, int[, str]) or None) | None | specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike |
image_data | bytes or str | None | Raw or Base64 representation of the image to put on button. Choose either filename or data |
image_filename | str | None | image filename if there is a button image. GIFs and PNGs only. |
image_size | (int, int) | (None, None) | Size of the image in pixels (width, height) |
image_subsample | int | None | amount to reduce the size of the image. Divides the size by this number. 2=1/2, 3=1/3, 4=1/4, etc |
initial_folder | str | None | starting path for folders and files |
k | str or int or tuple or object | None | Same as the Key. You can use either k or key. Which ever is set will be used. |
key | str or int or tuple or object | None | Used with window.find_element and with return values to uniquely identify this element to uniquely identify this element |
metadata | Any | None | User metadata that can be set to ANYTHING |
pad | (int, int or (int, int),(int,int) or int,(int,int)) or ((int, int),int) | None | Amount of padding to put around element in pixels (left/right, top/bottom) or ((left, right), (top, bottom)) or an int. If an int, then it's converted into a tuple (int, int) |
size | (int or None, int or None) or (None, None) | (None, None) | (w, h) w=characters-wide, h=rows-high |
size_px | (int, int) or (None, None) | (None, None) | w=pixels-wide, h=pixels-high |
target | str or (int, int) | (None, None) | key or (row,col) target for the button. Note that -1 for column means 1 element to the left of this one. The constant ThisRow is used to indicate the current row. The Button itself is a valid target for some types of button |
tooltip | str | None | text, that will appear when mouse hovers over the element |
visible | bool | True | set visibility state of the element |
Class Properties
This class has no public properties
Class Methods
def click
def expand
def get_stylesheet
def get_text
def set_focus
def set_stylesheet
def update
click
Generates a click of the button as if the user clicked the button Calls the invoke method for the button
expand
WARNING - NOT USED IN PySimpleGUIQt port. Provided as dummy method
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
expand_row | bool | True | If True the row containing the element will also expand. Without this your element is "trapped" within the row |
expand_x | bool | False | If True Element will expand in the Horizontal directions |
expand_y | bool | False | If True Element will expand in the Vertical directions |
RETURN | None | None |
get_stylesheet
Returns the stylesheet for element's associated Qt Widget
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
RETURN | str | stylesheet |
get_text
Returns the current text shown on a button
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
RETURN | str | The text currently displayed on the button |
set_focus
Sets the current focus to be on this element
set_stylesheet
Sets the stylesheet for a Qt Widget
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
stylesheet | str | Stylesheet (string) to set stylesheet to |
update
Changes some of the settings for the Button Element. Must call Window.Read
or Window.Finalize
prior
Changes will not be visible in your window until you call window.read or window.refresh.
If you change visibility, your element may MOVE.
update(
text = None,
button_color = (None, None),
disabled = None,
image_data = None,
image_filename = None,
font = None,
visible = None
)
Parameter Descriptions
Name | Type | Default | Description |
---|---|---|---|
button_color | (str, str) or str or (int, int) or None | (None, None) | Color of button. default is from theme or the window. Easy to remember which is which if you say "ON" between colors. "red" on "green". Normally a tuple, but can be a simplified-button-color-string "foreground on background". Can be a single color if want to set only the background. |
disabled | (bool or str) | None | True/False to enable/disable at the GUI level. Use BUTTON_DISABLED_MEANS_IGNORE to ignore clicks (won't change colors) |
font | (str or (str, int[, str]) or None) | None | specifies the font family, size. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike |
image_data | bytes or str | None | Raw or Base64 representation of the image to put on button. Choose either filename or data |
image_filename | str | None | image filename if there is a button image. GIFs and PNGs only. |
text | str | None | sets button text |
visible | bool | None | control visibility of element |