0
点赞
收藏
分享

微信扫一扫

第二章 PySimpleGui Button元素详解

暮晨夜雪 2022-01-08 阅读 94

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录


前言

基于官方链接:Call reference - PySimpleGUI

一、Button Element

按钮元素 - 定义所有可能的按钮。 Submit、FileBrowse 等可创建快捷一个 Button。

二、使用步骤

1.参数

Button(button_text = "",
    button_type = 7,
    target = (None, None),
    tooltip = None,
    file_types = (('ALL Files', '*.* *'),),
    initial_folder = None,
    default_extension = "",
    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),
    s = (None, None),
    auto_size_button = None,
    button_color = None,
    disabled_button_color = None,
    highlight_colors = None,
    mouseover_colors = (None, None),
    use_ttk_buttons = None,
    font = None,
    bind_return_key = False,
    focus = False,
    pad = None,
    p = None,
    key = None,
    k = None,
    right_click_menu = None,
    expand_x = False,
    expand_y = False,
    visible = True,
    metadata = None)

2.参数说明

TypeNameMeaning
strbutton_textText to be displayed on the button 按钮上显示的文本
intbutton_typeYou should NOT be setting this directly. ONLY the shortcut functions set this 
str or (int, int)targetkey 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
strtooltiptext, that will appear when mouse hovers over the element
Tuple[(str, str), ...]file_typesthe filetypes that will be used to match files. To indicate all files: (("ALL Files", ". *"),). Note - NOT SUPPORTED ON MAC
strinitial_folderstarting path for folders and files
strdefault_extensionIf no extension entered by user, add this to filename (only used in saveas dialogs)
(bool or str)disabledIf True button will be created disabled. If BUTTON_DISABLED_MEANS_IGNORE then the button will be ignored rather than disabled using tkinter
boolchange_submitsDO NOT USE. Only listed for backwards compat - Use enable_events instead
boolenable_eventsTurns on the element specific events. If this button is a target, should it generate an event when filled in
strimage_filenameimage filename if there is a button image. GIFs and PNGs only.
bytes or strimage_dataRaw or Base64 representation of the image to put on button. Choose either filename or data
(int, int)image_sizeSize of the image in pixels (width, height)
intimage_subsampleamount to reduce the size of the image. Divides the size by this number. 2=1/2, 3=1/3, 4=1/4, etc
intborder_widthwidth of border around button in pixels
(int or None, int or None) or (None, None) or intsize(w, h) w=characters-wide, h=rows-high. If an int instead of a tuple is supplied, then height is auto-set to 1
(int or None, int or None) or (None, None) or intsSame as size parameter. It's an alias. If EITHER of them are set, then the one that's set will be used. If BOTH are set, size will be used
boolauto_size_buttonif True the button size is sized to fit the text
(str, str) or str or (int, int) or Nonebutton_colorColor 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.
(str, str) or strdisabled_button_colorcolors to use when button is disabled (text, background). Use None for a color if don't want to change. Only ttk buttons support both text and background colors. tk buttons only support changing text color
(str, str)highlight_colorscolors to use when button has focus (has focus, does not have focus). None will use colors based on theme. Only used by Linux and only for non-TTK button
(str, str) or strmouseover_colorsImportant difference between Linux & Windows! Linux - Colors when mouse moved over button. Windows - colors when button is pressed. The default is to switch the text and background colors (an inverse effect)
booluse_ttk_buttonsTrue = use ttk buttons. False = do not use ttk buttons. None (Default) = use ttk buttons only if on a Mac and not with button images
(str or (str, int[, str]) or None)fontspecifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike
boolbind_return_keyIf True the return key will cause this button to be pressed
boolfocusif True, initial focus will be put on this button
(int, int or (int, int),(int,int) or int,(int,int)) or ((int, int),int) or intpadAmount 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)
(int, int or (int, int),(int,int) or int,(int,int)) or ((int, int),int) or intpSame as pad parameter. It's an alias. If EITHER of them are set, then the one that's set will be used. If BOTH are set, pad will be used
str or int or tuple or objectkeyUsed with window.find_element and with return values to uniquely identify this element to uniquely identify this element
str or int or tuple or objectkSame as the Key. You can use either k or key. Which ever is set will be used.
List[List[ List[str] or str ]]right_click_menuA list of lists of Menu items to show when this element is right clicked. See user docs for exact format.
boolexpand_xIf True the element will automatically expand in the X direction to fill available space
boolexpand_yIf True the element will automatically expand in the Y direction to fill available space
boolvisibleset visibility state of the element
AnymetadataUser metadata that can be set to ANYTHING

总结

提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。

举报

相关推荐

TypeScript 第二章

第二章 翻译

第二章 资产

第二章 IDLE

第二章-表格

第二章:Hello,Flutter(二)

Java第二章总结

0 条评论