PySimpleGUI.InputText()输入框参数详解

PySimpleGUI.py原文说明

    def __init__(self, default_text='', size=(None, None), s=(None, None), disabled=False, password_char='',
                 justification=None, background_color=None, text_color=None, font=None, tooltip=None, border_width=None,
                 change_submits=False, enable_events=False, do_not_clear=True, key=None, k=None, focus=False, pad=None, p=None,
                 use_readonly_for_disable=True, readonly=False, disabled_readonly_background_color=None, disabled_readonly_text_color=None, expand_x=False, expand_y=False,
                 right_click_menu=None, visible=True, metadata=None):
        """
        :param default_text:                       Text initially shown in the input box as a default value(Default value = ''). Will automatically be converted to string
        :type default_text:                        (Any)
        :param size:                               w=characters-wide, h=rows-high. If an int is supplied rather than a tuple, then a tuple is created width=int supplied and heigh=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 (Default = False)
        :type disabled:                            (bool)
        :param password_char:                      Password character if this is a password field (Default value = '')
        :type password_char:                       (char)
        :param justification:                      justification for data display. Valid choices - left, right, center
        :type justification:                       (str)
        :param background_color:                   color of background in one of the color formats
        :type background_color:                    (str)
        :param text_color:                         color of the text
        :type text_color:                          (str)
        :param font:                               specifies the font family, size. 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 tooltip:                            text, that will appear when mouse hovers over the element
        :type tooltip:                             (str)
        :param border_width:                       width of border around element in pixels
        :type border_width:                        (int)
        :param change_submits:                     * DEPRICATED DO NOT USE. Use `enable_events` instead
        :type change_submits:                      (bool)
        :param enable_events:                      If True then changes to this element are immediately reported as an event. Use this instead of change_submits (Default = False)
        :type enable_events:                       (bool)
        :param do_not_clear:                       If False then the field will be set to blank after ANY event (button, any event) (Default = True)
        :type do_not_clear:                        (bool)
        :param key:                                Value that uniquely identifies this element from all other elements. Used when Finding an element or in return values. Must be unique to the window
        :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 focus:                              Determines if initial focus should go to this element.
        :type focus:                               (bool)
        :param pad:                                Amount of padding to put around element. Normally (horizontal pixels, vertical pixels) but can be split apart further into ((horizontal left, horizontal right), (vertical above, vertical below)). If int is given, then converted to tuple (int, int) with the value provided duplicated
        :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 use_readonly_for_disable:           If True (the default) tkinter state set to 'readonly'. Otherwise state set to 'disabled'
        :type use_readonly_for_disable:            (bool)
        :param readonly:                           If True tkinter state set to 'readonly'.  Use this in place of use_readonly_for_disable as another way of achieving readonly.  Note cannot set BOTH readonly and disabled as tkinter only supplies a single flag
        :type readonly:                            (bool)
        :param disabled_readonly_background_color: If state is set to readonly or disabled, the color to use for the background
        :type disabled_readonly_background_color:  (str)
        :param disabled_readonly_text_color:       If state is set to readonly or disabled, the color to use for the text
        :type disabled_readonly_text_color:        (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 (Default = True)
        :type visible:                             (bool)
        :param metadata:                           User metadata that can be set to ANYTHING
        :type metadata:                            (Any)
        """

我将上面的信息整理了下

参数名值类型说明
default_text:(Any)输入框默认值
size:(int,int)|(int,None)|intw=字符宽,h=行高。如果提供了int而不是元组,则创建一个元组,提供width=int和heigh=1
s:(int,int)|(None,None)|intsize参数相同。这是一个别名
disabled:(bool)设置元素的禁用状态(默认值为False)
password_char:(char)密码字符(如果这是密码字段)(默认值=“”)
justification:(str)数据显示的正当性。有效的选择-左、右、中
background_color:(str)背景颜色
text_color:(str)文本的颜色
font:(stror(str,int[,str])orNone)指定字体系列和大小
tooltip:(str)文本,当鼠标悬停在元素上时将显示
border_width:(int)元素周围边框的宽度(以像素为单位)
change_submits:(bool)*未经处理的请勿使用。改为使用“enable_events”
enable_events:(bool)如果为True,则对该元素的更改将立即报告为事件。使用此项而不是change_submits(默认值为False)
do_not_clear:(bool)如果为False,则在其他事件(按钮,任何事件)之后该字段将设置为空白(默认值=True
key:str|int|tuple|object从所有其他元素中唯一标识此元素的值。在查找元素或返回值时使用。必须是窗口唯一的
k:str|int|tuple|objectkey相同。您可以使用kkey。将使用已设置的。
focus:(bool)确定初始焦点是否应转到要素
pad:(int,int)or((int,int),(int,int))or(int,(int,int))or((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参数相同。这是一个别名。
use_readonly_for_disable:(bool)如果为True(默认值),则tkinter-state设置为“readonly”。否则,状态设置为“已禁用”
readonly:(bool)如果Truetkinterstate设置为“readonly”。用它代替Use_readonly_for_disable作为实现只读的另一种方式。
disabled_readonly_background_color:(str)如果状态设置为只读或禁用,则用于背景的颜色
disabled_readonly_text_color:(str)如果状态被设置为只读或禁用,用于文本的颜色
expand_x:(bool)如果为True,则图元将自动在X方向上展开以填充可用空间
expand_y:(bool)如果为True,则图元将自动在Y方向上展开以填充可用空间
right_click_menu:List[List[List[str]|str]]右键单击此元素时要显示的菜单项列表。有关确切格式,请参阅用户文档。
visible:(bool)设置图元的可见性状态(默认值为True)
metadata:(Any)可以设置为ANYTHING的用户元数据

参数使用样例

    [PySimpleGUI.InputText(text,
                   key="-Text-",                # 元素唯一标识符,用于元素的定位
                   size=(None, None),           # 元素宽度,行高(int, int)
                   text_color=None,             # 输入框里的文本颜色
                   background_color=None,       # 输入框的颜色
                   justification=None,          # 对齐方式: "left", "right", "center"
                   disabled=None,               # 元素禁用,如果为True则禁用,无法输入任何值
                   disable_readonly_background_color=None,  # 元素禁用时的背景颜色设定
                   disable_readonly_text_color=None,        # 元素禁用时的文本颜色设定
                   password_char=""             # 密码字符,一般设置为*
                   font=("宋体", 20),            # 设定文字字体,大小,font="宋体",font=("宋体", int) or font["宋体", int]
                   border_width=20,             # 输入框边界线宽度设定
                   enable_events=False,         # bool: 输入框的事件属性,设定为True时,输入值会发生事件
                   do_not_clear=True,           # bool: 输入框内容不被清除,如果为False,一旦发生事件,该输入框内的值会被清楚        
                   focus=False,                # 设定焦点,如果为True,则光标显示在此输入框
                   pad=None,                    # 元素间隔设定  记住左右上下((int, int), (int, int))当左右或上下值一样时(int, int)
                   right_click_menu=None,       # 右击可以调出菜单 list[list[Union[List[str],str]]]
                   grab=None,                   # 如果为真,点击此元素可以移动拖拽窗口
                   tooltip=None,                # str: 悬浮文本,当光标置于该元素上方,会显示设定的文本
                   visible=True)]               # bool: 元素可见状态
]

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

  • 24
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是一个简单的HTML5表单,包含所有要求的元素: ```html <!DOCTYPE html> <html> <head> <title>注册表单</title> <meta charset="utf-8"> </head> <body> <form> <label for="email">邮件地址:</label> <input type="text" id="email" name="email" required> @ <input type="text" id="email-domain" name="email-domain" required> . <input type="text" id="email-tld" name="email-tld" required> <br><br> <label for="password">密码:</label> <input type="password" id="password" name="password" required> <br><br> <label for="confirm-password">确认密码:</label> <input type="password" id="confirm-password" name="confirm-password" required> <br><br> <label for="phone">手机号码:</label> <input type="tel" id="phone" name="phone" pattern="[0-9]{11}" required> <br><br> <label for="captcha">验证码:</label> <input type="text" id="captcha" name="captcha" required> <img src="captcha.php" alt="验证码" onclick="this.src='captcha.php?'+Math.random()"> <button type="button" onclick="this.previousSibling.src='captcha.php?'+Math.random()">换一张</button> <br><br> <button type="button">免费获取验证码</button> <label for="sms-code">短信验证码:</label> <input type="text" id="sms-code" name="sms-code" required> <br><br> <label for="terms">同意服务条款:</label> <input type="checkbox" id="terms" name="terms" required> <br><br> <button type="submit">立即注册</button> </form> </body> </html> ``` 解释一下: 1. 邮件地址的三个部分分别是`email`、`email-domain`和`email-tld`,都是必填项。 2. 密码输入框使用`type="password"`。 3. 确认密码输入框与密码输入框相同。 4. 手机号码输入框使用`type="tel"`和`pattern="[0-9]{11}"`,表示必须是11位数字。 5. 验证码使用一个`img`标签显示图片,并在`onclick`事件中生成新的验证码图片。 6. 免费获取验证码使用一个普通的`button`标签。 7. 短信验证码输入框与其他输入框相同。 8. 同意服务条款使用一个`checkbox`标签,并添加`required`属性。 9. 立即注册使用一个普通的`button`标签,不是`type="submit"`,因为需要添加JavaScript代码来验证表单。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值