PySimpleGUI.DropDown() / PySimpleGUI.Drop()下拉菜单的设定方法

本文解析了PySimpleGUI中的ComboBox元素,强调了它与Listbox的不同之处,即允许单选输入但不支持多选,以及详细介绍了其参数如values、default_value、size、events等的使用方法和功能。
摘要由CSDN通过智能技术生成

此方法与PySimpleGUI.Listbox()列表元素的最大区别在于,该方法可以输入(但是不能多选),而Listbox取得的值是存放在列表里面,但是Combo取得的值是对象本身

PySimpleGUI.py原文说明

class Combo(Element):
    """
    ComboBox Element - A combination of a single-line input and a drop-down menu. User can type in their own value or choose from list.
    """

    def __init__(self, values, default_value=None, size=(None, None), s=(None, None), auto_size_text=None, background_color=None, text_color=None, button_background_color=None, button_arrow_color=None, bind_return_key=False, change_submits=False, enable_events=False, disabled=False, key=None, k=None, pad=None, p=None, expand_x=False, expand_y=False, tooltip=None, readonly=False, font=None, visible=True, metadata=None):
        """
        :param values:                  values to choose. While displayed as text, the items returned are what the caller supplied, not text
        :type values:                   List[Any] or Tuple[Any]
        :param default_value:           Choice to be displayed as initial value. Must match one of values variable contents
        :type default_value:            (Any)
        :param size:                    width, height. Width = characters-wide, height = NOTE it's the number of entries to show in the list. If an Int is passed rather than a tuple, then height is auto-set to 1 and width is value of the int
        :type size:                     (int, int)  | (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, int)  | (None, None) | int
        :param auto_size_text:          True if element should be the same size as the contents
        :type auto_size_text:           (bool)
        :param background_color:        color of background
        :type background_color:         (str)
        :param text_color:              color of the text
        :type text_color:               (str)
        :param button_background_color: The color of the background of the button on the combo box
        :type button_background_color:  (str)
        :param button_arrow_color:      The color of the arrow on the button on the combo box
        :type button_arrow_color:       (str)
        :param bind_return_key:         If True, then the return key will cause a the Combo to generate an event
        :type bind_return_key:          (bool)
        :param change_submits:          DEPRICATED DO NOT USE. Use `enable_events` instead
        :type change_submits:           (bool)
        :param enable_events:           Turns on the element specific events. Combo event is when a choice is made
        :type enable_events:            (bool)
        :param disabled:                set disable state for element
        :type disabled:                 (bool)
        :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 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 tooltip:                 text that will appear when mouse hovers over this element
        :type tooltip:                  (str)
        :param readonly:                make element readonly (user can't change). True means user cannot change
        :type readonly:                 (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 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] or Tuple[Any]要选择的值。当显示为文本时,返回的项目是调用者提供的,而不是文本
default_value:(Any)要显示为初始值的选项。必须与值变量内容之一匹配
size:(int, int)| (None, None) | int 宽度、高度。宽度=字符宽度,高度=注意,这是要在列表中显示的条目数。若传递的是Int而不是元组,那个么高度会自动设置为1,宽度是Int的值
s:(int, int)| (None, None) | int 与size参数相同。这是一个别名。如果设置了其中任何一个,则将使用设置的那个。如果设置了BOTH,将使用大小
auto_size_text:(bool) 如果元素的大小应与内容的大小相同,则为True
background_color:(str)背景颜色
text_color:(str)文本的颜色
button_background_color:(str)组合框上按钮的背景颜色
button_arrow_color:(str)组合框上按钮上箭头的颜色
bind_return_key:(bool) 如果为True,则返回键将导致组合框生成事件
change_submits:(bool) 未经处理的请勿使用。改为使用“enable_events”
enable_events:(bool) 打开特定于元素的事件。组合事件是在做出选择时发生的
disabled:(bool) 设置元素的禁用状态
key:str | int | tuple | object 与window.find_element和返回值一起使用,以唯一标识此元素
k:str | int | tuple | object 与key相同。您可以使用k或key。将使用已设置的。
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,将使用衬垫
expand_x:(bool) 如果为True,则图元将自动在X方向上展开以填充可用空间
expand_y:(bool) 如果为True,则图元将自动在y方向上展开以填充可用空间
tooltip:(str)当鼠标悬停在此元素上时将显示的文本
readonly:(bool) 使元素只读(用户不能更改)。True表示用户无法更改
font:(str or (str, int[, str]) or None) 指定字体系列、大小等。元组或单字符串格式的“名称大小样式”。样式:斜体*罗马粗体普通下划线加粗
visible:(bool) 设置图元的可见性状态
metadata:(Any)可以设置为ANYTHING的用户元数据

 参数使用样例

        [pg.Drop(list_A,
                 size=(1, 2),
                 auto_size_text=True,
                 background_color="",
                 text_color="",
                 enable_events=False,
                 disabled=False,
                 pad=None,
                 tooltip=None,
                 readonly=False,        # 元素只读属性,只能选择不能输入内容
                 font=None,
                 visible=True
                 )]
]

运行结果样例

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值