KIVY Button¶

Button — Kivy 2.3.0 documentation

Button

Jump to API ⇓


Module: kivy.uix.button

Added in 1.0.0

_images/button.jpg

The Button is a Label with associated actions that are triggered when the button is pressed (or released after a click/touch). To configure the button, the same properties (padding, font_size, etc) and sizing system are used as for the Label class:
按钮(Button)是一个带有相关动作的标签(Label),这些动作在按钮被按下(或点击/触摸后释放)时触发。为了配置按钮,我们使用了与标签(Label)类相同的属性(如内边距padding、字体大小font_size等)和尺寸系统。

button = Button(text='Hello world', font_size=14)

To attach a callback when the button is pressed (clicked/touched), use bind:
当按钮被按下(点击/触摸)时,要附加一个回调函数,可以使用bind方法。

def callback(instance):
    print('The button <%s> is being pressed' % instance.text)

btn1 = Button(text='Hello world 1')
btn1.bind(on_press=callback)
btn2 = Button(text='Hello world 2')
btn2.bind(on_press=callback)

If you want to be notified every time the button state changes, you can bind to the Button.state property:
如果你想要在每次按钮状态发生变化时都收到通知,你可以将事件绑定到Button.state属性上:

def callback(instance, value):
    print('My button <%s> state is <%s>' % (instance, value))
btn1 = Button(text='Hello world 1')
btn1.bind(state=callback)

Kv Example:

Button:
    text: 'press me'
    on_press: print("ouch! More gently please")
    on_release: print("ahhh")
    on_state:
        print("my current state is {}".format(self.state))

APIHide Description ⇑


class kivy.uix.button.Button(**kwargs)

Bases: kivy.uix.behaviors.button.ButtonBehaviorkivy.uix.label.Label

Button class, see module documentation for more information.

Changed in version 1.8.0: The behavior / logic of the button has been moved to ButtonBehaviors.

background_color

Background color, in the format (r, g, b, a).  背景颜色,格式为(r, g, b, a)。

This acts as a multiplier to the texture color. The default texture is grey, so just setting the background color will give a darker result. To set a plain color, set the background_normal to ''.
它作为纹理颜色的一个乘数因子。默认纹理是灰色的,所以仅仅设置背景颜色会得到一个更暗的结果。要设置纯色,请将background_normal属性设置为空字符串('')。

New in version 1.0.8.  此功能在版本1.0.8中新增。

The background_color is a ColorProperty and defaults to [1, 1, 1, 1].
background_color是一个ColorProperty,其默认值为[1, 1, 1, 1](即白色,完全不透明)。

Changed in version 2.0.0: Changed from ListProperty to ColorProperty.
在版本2.0.0中更改:从ListProperty更改为ColorProperty。

background_disabled_down

Background image of the button used for the default graphical representation when the button is disabled and pressed.

New in version 1.8.0.

background_disabled_down is a StringProperty and defaults to ‘atlas://data/images/defaulttheme/button_disabled_pressed’.

background_disabled_normal

Background image of the button used for the default graphical representation when the button is disabled and not pressed.
按钮的背景图像,用于在按钮被禁用且被按下时的默认图形表示。

New in version 1.8.0.   此功能在版本1.8.0中新增。

background_disabled_normal is a StringProperty and defaults to ‘atlas://data/images/defaulttheme/button_disabled’.

background_down

Background image of the button used for the default graphical representation when the button is pressed.

按钮的背景图像,用于按钮被按下时的默认图形表示。

New in version 1.0.4.  此功能在版本1.0.4中新增。

background_down is a StringProperty and defaults to ‘atlas://data/images/defaulttheme/button_pressed’.
background_disabled_down是一个StringProperty,其默认值为'atlas://data/images/defaulttheme/button_disabled_pressed'

background_normal

Background image of the button used for the default graphical representation when the button is not pressed.
按钮的背景图像,用于按钮未被按下时的默认图形表示。

New in version 1.0.4.   此功能在版本1.0.4中新增。

background_normal is a StringProperty and defaults to ‘atlas://data/images/defaulttheme/button’.
background_normal是一个StringProperty,其默认值为  'atlas://data/images/defaulttheme/button'

border

Border used for BorderImage graphics instruction. Used with background_normal and background_down. Can be used for custom backgrounds.
边框,用于BorderImage图形指令。与background_normalbackground_down一起使用。可用于自定义背景。

It must be a list of four values: (bottom, right, top, left). Read the BorderImage instruction for more information about how to use it.
它必须是一个包含四个值的列表:(底部, 右侧, 顶部, 左侧)。要获取更多关于如何使用它的信息,请阅读BorderImage指令的说明。

border is a ListProperty and defaults to (16, 16, 16, 16)
border是一个ListProperty,其默认值为(16, 16, 16, 16)。

<think>好的,用户想了解MongoDB Stitch的功能和用法。首先,我需要回忆一下MongoDB Stitch是什么。根据之前的引用,Stitch是MongoDB提供的后端即服务(BaaS),帮助开发者快速构建应用而无需管理底层基础设施。用户可能需要知道它的核心功能、如何集成以及使用场景。 首先,查看引用中的资料。引用[3]提到Stitch JavaScript SDK用于在JavaScript应用中集成,可能需要介绍SDK的使用方法。引用[4]提到整合MongoDB和Amazon Kinesis,可能涉及数据流的处理,这可以作为应用场景的例子。引用[1]和[2]提供了MongoDB的基本概念和文档资源,需要确保回答中的术语准确,并引导用户查阅官方文档。 接下来,组织回答结构。用户要求功能和用法指南,应该分点说明核心功能,比如数据访问控制、服务集成、无服务器函数、触发器、身份验证等。然后分步骤说明使用指南,包括环境准备、数据建模、配置规则、编写函数、集成外部服务等。每个部分需要结合引用内容,例如在说明数据访问控制时引用[3]的SDK部分,在服务集成时提到引用[4]的Kinesis整合。 需要确保使用正确的LaTeX格式,比如内联变量用$...$,但可能在这个回答中涉及较少数学公式,更多是技术术语。如果有代码示例,需要用代码块,但用户没有具体请求代码,可能不需要。不过,可以提到SDK的使用,如引用[3]中的JavaScript SDK。 可能还需要生成相关问题,比如如何配置触发器,如何与AWS服务集成,身份验证机制有哪些,适合移动应用开发吗,以及性能优化方法。这些问题应基于回答内容中的关键点,引导用户进一步探索。 最后,检查引用标注是否正确,每个引用来源是否在末尾正确对应,比如引用[3]和[4]在相关部分末尾添加标识。确保回答结构清晰,分点明确,语言简洁,符合用户要求的中文回答。</think>### MongoDB Stitch 功能与使用指南 #### 一、核心功能 1. **无服务器后端服务** MongoDB Stitch 提供后端即服务(BaaS),开发者无需管理服务器即可处理数据存储、用户认证等任务。例如,通过 Stitch 可直接访问 MongoDB 数据库,并集成第三方服务(如 AWS Kinesis)实现数据流处理[^4]。 2. **数据访问控制** 支持细粒度权限管理,通过规则(Rules)定义集合或字段级别的访问权限。例如: ```json { "roles": [{"name": "readOnly", "apply_when": {}, "read": true}] } ``` 3. **服务集成** 可无缝集成外部服务(如 AWS、Twilio、HTTP APIs),通过 Stitch 的 `Services` 功能调用 API。例如,将 MongoDB 数据实时同步到 Amazon Kinesis 进行流分析。 4. **无服务器函数(Functions)** 支持 JavaScript 编写函数,直接在 Stitch 界面部署,用于处理业务逻辑或数据转换。例如: ```javascript exports = function(data) { return context.services.get("mongodb").db("mydb").collection("users").insertOne(data); }; ``` 5. **实时触发器(Triggers)** 基于数据库变更(如插入、更新)触发自定义操作。例如,当新文档插入集合时,自动发送通知或更新关联数据[^3]。 #### 二、使用指南 1. **环境准备** - 在 MongoDB Atlas 控制台启用 Stitch 服务。 - 安装 Stitch CLI 或使用 Stitch JavaScript SDK[^3]。 2. **数据建模与访问规则** - 在 Atlas 中创建数据库和集合。 - 通过 `Rules` 配置访问权限(如仅允许认证用户读写特定字段)。 3. **配置服务集成** - 在 `Services` 中添加第三方服务(如 AWS),配置 API 密钥或 OAuth。 - 通过 `HTTP Service` 调用外部 REST API。 4. **编写无服务器函数** - 在 `Functions` 中创建 JavaScript 函数,使用 `context` 对象调用数据库或服务: $$ \text{示例:context.services.get("aws-s3").uploadFile(bucket, key, data)} $$ 5. **设置实时触发器** - 在 `Triggers` 中定义触发器类型(如 Database Trigger),关联集合和触发条件。 - 绑定到指定函数实现自动化流程。 #### 三、典型应用场景 1. **移动应用后端** 快速实现用户注册、数据存储及推送通知,无需自建服务器[^3]。 2. **物联网(IoT)数据流处理** 结合 Amazon Kinesis 处理设备实时数据,存储至 MongoDB 并触发分析任务。 3. **微服务架构** 通过 Stitch Functions 封装业务逻辑,降低服务间耦合度。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xinzheng新政

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值