PySimpleGUI.py原文说明
class Button(Element):
"""
Button Element - Defines all possible buttons. The shortcuts such as Submit, FileBrowse, ... each create a Button
"""
def __init__(self, button_text='', button_type=BUTTON_TYPE_READ_FORM, target=(None, None), tooltip=None,
file_types=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, image_source=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):
"""
:param button_text: Text to be displayed on the button
:type button_text: (str)
:param button_type: You should NOT be setting this directly. ONLY the shortcut functions set this
:type button_type: (int)
:param target: 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
:type target: str | (int, int)
:param tooltip: text, that will appear when mouse hovers over the element
:type tooltip: (str)
:param file_types: the filetypes that will be used to match files. To indicate all files: (("ALL Files", "*.* *"),). NOT avoilable on the MAC
:type file_types: Tuple[(str, str), ...]
:param initial_folder: starting path for folders and files
:type initial_folder: (str)
:param default_extension: If no extension entered by user, add this to filename (only used in saveas dialogs)
:type default_extension: (str)
:param disabled: If True button will be created disabled. If BUTTON_DISABLED_MEANS_IGNORE then the button will be ignored rather than disabled using tkinter
:type disabled: (bool | str)
:param change_submits: DO NOT USE. Only listed for backwards compat - Use enable_events instead
:type change_submits: (bool)
:param enable_events: Turns on the element specific events. If this button is a target, should it generate an event when filled in
:type enable_events: (bool)
:param image_source: Image to place on button. Use INSTEAD of the image_filename and image_data. Unifies these into 1 easier to use parm
:type image_source: (str | bytes)
:param image_filename: image filename if there is a button image. GIFs and PNGs only.
:type image_filename: (str)
:param image_data: Raw or Base64 representation of the image to put on button. Choose either filename or data
:type image_data: bytes | str
:param image_size: Size of the image in pixels (width, height)
:type image_size: (int, int)
:param image_subsample: amount to reduce the size of the image. Divides the size by this number. 2=1/2, 3=1/3, 4=1/4, etc
:type image_subsample: (int)
:param border_width: width of border around button in pixels
:type border_width: (int)
:param size: (w, h) w=characters-wide, h=rows-high. If an int instead of a tuple is supplied, then height is auto-set to 1
:type size: (int | None, int | None) | (None, None) | int
:param s: Same 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
:type s: (int | None, int | None) | (None, None) | int
:param auto_size_button: if True the button size is sized to fit the text
:type auto_size_button: (bool)
:param button_color: 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.
:type button_color: (str, str) | str | (int, int) | None
:param disabled_button_color: colors 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
:type disabled_button_color: (str, str) | str
:param highlight_colors: colors 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
:type highlight_colors: (str, str)
:param mouseover_colors: Important 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)
:type mouseover_colors: (str, str) | str
:param use_ttk_buttons: True = use ttk buttons. False = do not use ttk buttons. None (Default) = use ttk buttons only if on a Mac and not with button images
:type use_ttk_buttons: (bool)
:param font: specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike
:type font: (str or (str, int[, str]) or None)
:param bind_return_key: If True the return key will cause this button to be pressed
:type bind_return_key: (bool)
:param focus: if True, initial focus will be put on this button
:type focus: (bool)
:param pad: 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)
:type pad: (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | int
:param p: Same 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
:type p: (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | int
:param key: Used with window.find_element and with return values to uniquely identify this element to uniquely identify this element
:type key: str | int | tuple | object
:param k: Same as the Key. You can use either k or key. Which ever is set will be used.
:type k: str | int | tuple | object
:param right_click_menu: A list of lists of Menu items to show when this element is right clicked. See user docs for exact format.
:type right_click_menu: List[List[ List[str] | str ]]
:param expand_x: If True the element will automatically expand in the X direction to fill available space
:type expand_x: (bool)
:param expand_y: If True the element will automatically expand in the Y direction to fill available space
:type expand_y: (bool)
:param visible: set visibility state of the element
:type visible: (bool)
:param metadata: User metadata that can be set to ANYTHING
:type metadata: (Any)
"""
我将上面的信息整理了下
参数名 | 值类型 | 说明 |
button_text: | (str) | 要显示在按钮上的文本 |
button_type: | (int) | 您不应该直接设置。只有快捷方式功能设置此 |
target: | str|(int,int) | 键或(row,col)按钮的目标。请注意,列的-1表示该列左侧的1个元素。常量ThisRow用于指示当前行。按钮本身是某些类型按钮的有效目标 |
tooltip: | (str) | 文本当鼠标悬停在元素上时将显示 |
file_types: | Tuple[(str,str),...] | 将用于匹配文件的文件类型。指示所有文件:((“allfiles”,“*.**”),)。在MAC上不可用 |
initial_folder: | (str) | 文件夹和文件的起始路径 |
default_extension: | (str) | 如果用户未输入扩展名,请将其添加到文件名中(仅在“另存为”对话框中使用) |
disabled: | (bool|str) | 如果True按钮将被创建为禁用。如果BUTTON_DISABLED_MEANS_IGNORE,则该按钮将被忽略,而不是使用tkinter禁用 |
change_submits: | (bool) | 不要使用。仅针对向后兼容列出-请改用enable_events |
enable_events: | (bool) | 打开特定于元素的事件。如果该按钮是目标,填写时是否应生成事件 |
image_source: | (str|bytes) | 要放置在按钮上的图像。使用图像文件名和图像数据的INSTEAD。将这些统一为1个更易于使用的parm |
image_filename: | (str) | 图像文件名(如果有按钮图像)。GIF和PNG只有 |
image_data: | bytes|str | 要放在按钮上的图像的原始或Base64表示形式。选择文件名或数据 |
image_size: | (int,int) | 图像的大小(以像素为单位)(宽度、高度) |
image_subsample: | (int) | 减少图像大小的量。将大小除以此数字。2=1/2、3=1/3、4=1/4等 |
border_width: | (int) | 按钮周围边框的宽度(以像素为单位) |
size: | (int|None,int|None)|(None,None)|int | (w,h)w=字符宽,h=行高。如果提供了int而不是元组,则高度自动设置为1 |
s: | (int|None,int|None)|(None,None)|int | 与尺寸参数相同。这是一个别名。如果设置了其中任何一个,则将使用设置的那个。如果设置了BOTH,将使用大小 |
auto_size_button: | (bool) | 如果为True,按钮大小将适合文本 |
button_color: | (str,str)|str|(int,int)|None | 按钮的颜色。默认为来自主题或窗口。如果你在两种颜色之间说“ON”,很容易记住哪个是哪个。“红色”在“绿色”上。通常是一个元组,但可以是一个简化的按钮颜色字符串“foreground-on-background”。如果只想设置背景,可以是单一颜色。 |
disabled_button_color: | (str,str)|str | 禁用按钮时要使用的颜色(文本、背景)。如果不想更改颜色,请使用“无”。只有ttk按钮同时支持文本和背景色。tk按钮仅支持更改文本颜色 |
highlight_colors: | (str,str) | 按钮有焦点(有焦点,没有焦点)时使用的颜色。没有将使用基于主题的颜色。仅用于Linux,仅用于非TTK按钮 |
mouseover_colors: | (str,str)|str | Linux和Windows之间的重要区别!Linux-鼠标移到按钮上时的颜色。Windows-按下按钮时的颜色。默认情况是切换文本和背景颜色(反向效果) |
use_ttk_buttons: | (bool) | True=使用ttk按钮。False=不使用ttk按钮。无(默认)=仅在Mac上使用ttk按钮,而不使用按钮图像 |
font: | (stror(str,int[,str])orNone) | 指定字体系列、大小等。元组或单字符串格式的“名称大小样式”。样式:斜体*罗马粗体普通下划线加粗 |
bind_return_key: | (bool) | 如果为True,回车键将导致按下此按钮 |
focus: | (bool) | 如果为True,初始焦点将放在该按钮上 |
pad: | (int,int)or((int,int),(int,int))or(int,(int,int))or((int,int),int)|int | 元素周围的填充量,以像素(左/右,上/下)或((左,右),(上,下))或int为单位。如果是int,则将其转换为元组(int,int) |
p: | (int,int)or((int,int),(int,int))or(int,(int,int))or((int,int),int)|int | 与pad参数相同。这是一个别名。如果设置了其中任何一个,则将使用设置的那个。如果设置了BOTH,将使用衬垫 |
key: | str|int|tuple|object | 与window.find_element和返回值一起使用以唯一标识此元素以唯一标识该元素 |
k: | str|int|tuple|object | 与key相同。您可以使用k或key。哪一个会被设定习惯于 |
right_click_menu: | List[List[List[str]|str]] | 右键单击此元素时要显示的菜单项列表。有关确切格式,请参阅用户文档。 |
expand_x: | (bool) | 如果为True,则图元将自动在X方向上展开以填充可用空间 |
expand_y: | (bool) | 如果为True,则图元将自动在Y方向上展开以填充可用空间 |
visible: | (bool) | 设置图元的可见性状态 |
metadata: | (Any) | 可以设置为ANYTHING的用户元数据 |
参数使用样例
pg.Button(button_text="",
Key=None,
tooltip=None, # 悬浮文本
disabled=False, # 元素禁用设定
image_filename=None, # 图片路径,按钮图片表示,和image_data二选一使用
image_data=None, # 图片base64格式,按钮用图片显示,和image_filename二选一使用
image_size=(None, None),
image_subsample=None, # 图片大小设定,为2时,原图片的二分之一大小:2=1/2, 3=1/3, 4=1/4, etc
border_width=None, # 按钮边界线设定
size=(None, None),
auto_size=None, # 按键上文本大小自动调节
button_color=("", ""), # 按键的颜色,前面是字体,后面是背景
disabled_button_color=None, # 按键禁用时显示的按钮颜色
font=None,
bind_return_key=False, # 绑定回车键,如果设定为True,回车键会使此元素被点击
focus=False,
pad=None)
]
参数写的不对勿喷,评论告诉我改下