PySimpleGUI.Listbox()列表元素的设定方法

PySimpleGUI.py原文说明

class Listbox(Element):
    """
    A List Box.  Provide a list of values for the user to choose one or more of.   Returns a list of selected rows
    when a window.read() is executed.
    """

    def __init__(self, values, default_values=None, select_mode=None, change_submits=False, enable_events=False,
                 bind_return_key=False, size=(None, None), s=(None, None), disabled=False, auto_size_text=None, font=None, no_scrollbar=False, horizontal_scroll=False,
                 background_color=None, text_color=None, highlight_background_color=None, highlight_text_color=None,
                 sbar_trough_color=None, sbar_background_color=None, sbar_arrow_color=None, sbar_width=None, sbar_arrow_width=None, sbar_frame_color=None, sbar_relief=None,
                 key=None, k=None, pad=None, p=None, tooltip=None, expand_x=False, expand_y=False,right_click_menu=None, visible=True, metadata=None):
        """
        :param values:                     list of values to display. Can be any type including mixed types as long as they have __str__ method
        :type values:                      List[Any] or Tuple[Any]
        :param default_values:             which values should be initially selected
        :type default_values:              List[Any]
        :param select_mode:                Select modes are used to determine if only 1 item can be selected or multiple and how they can be selected.   Valid choices begin with "LISTBOX_SELECT_MODE_" and include: LISTBOX_SELECT_MODE_SINGLE LISTBOX_SELECT_MODE_MULTIPLE LISTBOX_SELECT_MODE_BROWSE LISTBOX_SELECT_MODE_EXTENDED
        :type select_mode:                 [enum]
        :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. Listbox generates events when an item is clicked
        :type enable_events:               (bool)
        :param bind_return_key:            If True, then the return key will cause a the Listbox to generate an event
        :type bind_return_key:             (bool)
        :param size:                       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, int) |  (int, 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, int)  | (None, None) | int
        :param disabled:                   set disable state for element
        :type disabled:                    (bool)
        :param auto_size_text:             True if element should be the same size as the contents
        :type auto_size_text:              (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 no_scrollbar:               Controls if a scrollbar should be shown.  If True, no scrollbar will be shown
        :type no_scrollbar:                (bool)
        :param horizontal_scroll:          Controls if a horizontal scrollbar should be shown.  If True a horizontal scrollbar will be shown in addition to vertical
        :type horizontal_scroll:           (bool)
        :param background_color:           color of background
        :type background_color:            (str)
        :param text_color:                 color of the text
        :type text_color:                  (str)
        :param highlight_background_color: color of the background when an item is selected. Defaults to normal text color (a reverse look)
        :type highlight_background_color:  (str)
        :param highlight_text_color:       color of the text when an item is selected. Defaults to the normal background color (a rerverse look)
        :type highlight_text_color:        (str)
        :param sbar_trough_color:           Scrollbar color of the trough
        :type sbar_trough_color:            (str)
        :param sbar_background_color:       Scrollbar color of the background of the arrow buttons at the ends AND the color of the "thumb" (the thing you grab and slide). Switches to arrow color when mouse is over
        :type sbar_background_color:        (str)
        :param sbar_arrow_color:            Scrollbar color of the arrow at the ends of the scrollbar (it looks like a button). Switches to background color when mouse is over
        :type sbar_arrow_color:             (str)
        :param sbar_width:                  Scrollbar width in pixels
        :type sbar_width:                   (int)
        :param sbar_arrow_width:            Scrollbar width of the arrow on the scrollbar. It will potentially impact the overall width of the scrollbar
        :type sbar_arrow_width:             (int)
        :param sbar_frame_color:            Scrollbar Color of frame around scrollbar (available only on some ttk themes)
        :type sbar_frame_color:             (str)
        :param sbar_relief:                 Scrollbar relief that will be used for the "thumb" of the scrollbar (the thing you grab that slides). Should be a constant that is defined at starting with "RELIEF_" - RELIEF_RAISED, RELIEF_SUNKEN, RELIEF_FLAT, RELIEF_RIDGE, RELIEF_GROOVE, RELIEF_SOLID
        :type sbar_relief:                  (str)
        :param key:                        Used with window.find_element and with return values 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 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 tooltip:                    text, that will appear when mouse hovers over the element
        :type tooltip:                     (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 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 visible:                    set visibility state of the element
        :type visible:                     (bool)
        :param metadata:                   User metadata that can be set to ANYTHING
        :type metadata:                    (Any)
        """

我将上面的信息整理了下

参数名值类型说明
values:List[Any]orTuple[Any]要显示的值列表。可以是任何类型,包括混合类型,只要它们具有__str__方法
default_values:List[Any]最初应该选择哪些值
select_mode:[enum]选择模式用于确定是只能选择一个项目还是多个项目,以及如何选择这些项目。有效的选择以“LISTBOX_SELECT_MODE_”开头,包括:LISTBOX_SELECT _MODE_SINGLE LISTBOX_SELECT_MODE_MULTIPLE LISTBOX_SELECT_MODE_BROWSE LISTBOX_ SELECT _MODE_EXTENDED
change_submits:(bool)不要使用。仅针对向后兼容列出-请改用enable_events
enable_events:(bool)打开特定于元素的事件。列表框在单击项目时生成事件
bind_return_key:(bool)如果为True,则返回键将导致Listbox生成事件
size:(int,int)|(int,None)|intw=字符宽,h=行高。如果提供的是int而不是元组,则高度自动设置为1
s:(int,int)|(None,None)|int与size参数相同。这是一个别名。如果设置了其中任何一个,则将使用设置的那个。如果设置了BOTH,将使用大小
disabled:(bool)设置元素的禁用状态
auto_size_text:(bool)如果元素的大小应与内容的大小相同,则为True
font:(stror(str,int[,str])orNone)指定字体系列、大小等。元组或单字符串格式的“名称大小样式”。样式:斜体*罗马粗体普通下划线加粗
no_scrollbar:(bool)控制是否应显示滚动条。如果为True,则不会显示滚动条
horizontal_scroll:(bool)控制是否应显示水平滚动条。如果为True,除了垂直滚动条外,还会显示水平滚动条
background_color:(str)背景颜色
text_color:(str)文本的颜色
highlight_background_color:(str)选择项目时背景的颜色。默认为正常文本颜色(反向外观)
highlight_text_color:(str)选择项目时文本的颜色。默认为正常背景色(重反转外观)
sbar_trough_color:(str)槽的滚动条颜色
sbar_background_color:(str)两端箭头按钮背景的滚动条颜色和“拇指”(你抓住并滑动的东西)的颜色。鼠标悬停时切换到箭头颜色
sbar_arrow_color:(str)滚动条末端箭头的滚动条颜色(看起来像一个按钮)。鼠标悬停时切换到背景色
sbar_width:(int)滚动条宽度(像素)
sbar_arrow_width:(int)滚动条上箭头的滚动条宽度。它可能会影响滚动条的整体宽度
sbar_frame_color:(str)滚动条滚动条周围边框的颜色(仅适用于某些ttk主题)
sbar_relief:(str)滚动条浮雕将用于滚动条的“拇指”(您抓取的幻灯片)。应为以“RELIEF_”开头定义的常量-RELIEF_RAISED、RELIEF_UNKEN、RELie_FLAT、RELIEF_RIDGE、RELIEF_GROOVE、RELEF_SOLID
key:str|int|tuple|object元素周围的填充量,以像素(左/右,上/下)或((左,右),(上,下))或int为单位。如果是int,则将其转换为元组(int,int)
k:str|int|tuple|object与pad参数相同。这是一个别名。如果设置了其中任何一个,则将使用设置的那个。如果设置了BOTH,将使用衬垫
pad:(int,int)or((int,int),(int,int))or(int,(int,int))or((int,int),int)|int与window.find_element和返回值一起使用以唯一标识此元素以唯一标识该元素
p:(int,int)or((int,int),(int,int))or(int,(int,int))or((int,int),int)|int与key相同。您可以使用k或key。哪一个会被设定习惯于
tooltip:(str)
expand_x:(bool)右键单击此元素时要显示的菜单项列表。有关确切格式,请参阅用户文档。
expand_y:(bool)如果为True,则图元将自动在X方向上展开以填充可用空间
right_click_menu:List[List[List[str]|str]]如果为True,则图元将自动在Y方向上展开以填充可用空间
visible:(bool)设置图元的可见性状态
metadata:(Any)可以设置为ANYTHING的用户元数据

参数使用样例

list_A = ['Copy', 'Paste', 'Select All', 'Cut']
[pg.Listbox(list_A, size=(80, 40),
            default_values=None,                # 打开时默认选中的值或者列表
            key=None,
            select_mode=None,                   # 鼠标选择模式,有效值有4中:
                                                # single, 单选,更换时点击选择
                                                # multiple, 可以多选,逐一点击选择
                                                # browse, 单选,鼠标按住也可以更换选择
                                                # extended, 可以多选,鼠标按住也可以扩展选择
            enable_events=False,                # 列表元素的事件属性,如果为True,点击时会返回key
            bind_return_key=True,               # 绑定回车键,如果为True回车键按下时,相当于此元素被点击
            disabled=False,
            auto_size_text=True,
            font=None,
            no_scrollbar=False,                 # 如果为True,则没有滚动条
            background_color="",
            text_color="",
            pad=None,
            tooltip=None,                       # 悬浮文本
            right_click_menu=None,              # 右击调出菜单
            visible=True
            )]

参数写的不对勿喷,评论告诉我改下

  • 24
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值