目录
控件¶
Widgets 是图形用户界面的元素,构成了 用户体验 的一部分。kivy.uix 模块包含了用于创建和管理 Widgets 的类。更多信息请参阅 Widget 类 文档。
Kivy 控件可以分为以下几类:
UX 组件:经典的用户界面组件,可直接组装以创建更复杂的组件。
布局(Layouts):布局控件本身不进行渲染,仅作为触发器,以特定方式排列其子控件。更多信息请参阅:此处布局文档。
复杂UX组件:由多个经典组件组合而成的非原子组件。我们称其为复杂,是因为它们的组装和使用方式不如经典组件那样通用。
行为控件:这些控件不进行渲染,而是作用于其子控件的图形指令或交互(触摸)行为。
屏幕管理器:管理屏幕以及从一个屏幕切换到另一个屏幕时的过渡效果。
: 屏幕管理器
- 行为
- 行为混入类
- 添加行为
ButtonBehaviorCodeNavigationBehaviorCompoundSelectionBehaviorCompoundSelectionBehavior.clear_selection()CompoundSelectionBehavior.deselect_node()CompoundSelectionBehavior.get_index_of_node()CompoundSelectionBehavior.get_selectable_nodes()CompoundSelectionBehavior.goto_node()CompoundSelectionBehavior.keyboard_selectCompoundSelectionBehavior.multiselectCompoundSelectionBehavior.nodes_order_reversedCompoundSelectionBehavior.page_countCompoundSelectionBehavior.right_countCompoundSelectionBehavior.scroll_countCompoundSelectionBehavior.select_node()CompoundSelectionBehavior.select_with_key_down()CompoundSelectionBehavior.select_with_key_up()CompoundSelectionBehavior.select_with_touch()CompoundSelectionBehavior.selected_nodesCompoundSelectionBehavior.text_entry_timeoutCompoundSelectionBehavior.touch_deselect_lastCompoundSelectionBehavior.touch_multiselectCompoundSelectionBehavior.up_count
CoverBehaviorDragBehaviorEmacsBehaviorFocusBehaviorFocusBehavior.focusFocusBehavior.focus_nextFocusBehavior.focus_previousFocusBehavior.focusedFocusBehavior.get_focus_next()FocusBehavior.get_focus_previous()FocusBehavior.hide_keyboard()FocusBehavior.ignored_touchFocusBehavior.input_typeFocusBehavior.is_focusableFocusBehavior.keyboardFocusBehavior.keyboard_modeFocusBehavior.keyboard_on_key_down()FocusBehavior.keyboard_on_key_up()FocusBehavior.keyboard_suggestionsFocusBehavior.show_keyboard()FocusBehavior.unfocus_on_touch
ToggleButtonBehaviorTouchRippleBehaviorTouchRippleBehavior.ripple_duration_inTouchRippleBehavior.ripple_duration_outTouchRippleBehavior.ripple_fade()TouchRippleBehavior.ripple_fade_from_alphaTouchRippleBehavior.ripple_fade_to_alphaTouchRippleBehavior.ripple_func_inTouchRippleBehavior.ripple_func_outTouchRippleBehavior.ripple_rad_defaultTouchRippleBehavior.ripple_scaleTouchRippleBehavior.ripple_show()
TouchRippleButtonBehavior- 按钮行为
- 代码导航行为
- 复合选择行为
- 复合选择概念
- 选择机制
- 示例
CompoundSelectionBehaviorCompoundSelectionBehavior.clear_selection()CompoundSelectionBehavior.deselect_node()CompoundSelectionBehavior.get_index_of_node()CompoundSelectionBehavior.get_selectable_nodes()CompoundSelectionBehavior.goto_node()CompoundSelectionBehavior.keyboard_selectCompoundSelectionBehavior.multiselectCompoundSelectionBehavior.nodes_order_reversedCompoundSelectionBehavior.page_countCompoundSelectionBehavior.right_countCompoundSelectionBehavior.scroll_countCompoundSelectionBehavior.select_node()CompoundSelectionBehavior.select_with_key_down()CompoundSelectionBehavior.select_with_key_up()CompoundSelectionBehavior.select_with_touch()CompoundSelectionBehavior.selected_nodesCompoundSelectionBehavior.text_entry_timeoutCompoundSelectionBehavior.touch_deselect_lastCompoundSelectionBehavior.touch_multiselectCompoundSelectionBehavior.up_count
- 覆盖行为
- 拖拽行为
- Emacs 行为
- 焦点行为
- 管理焦点
- 初始化焦点
FocusBehaviorFocusBehavior.focusFocusBehavior.focus_nextFocusBehavior.focus_previousFocusBehavior.focusedFocusBehavior.get_focus_next()FocusBehavior.get_focus_previous()FocusBehavior.hide_keyboard()FocusBehavior.ignored_touchFocusBehavior.input_typeFocusBehavior.is_focusableFocusBehavior.keyboardFocusBehavior.keyboard_modeFocusBehavior.keyboard_on_key_down()FocusBehavior.keyboard_on_key_up()FocusBehavior.keyboard_suggestionsFocusBehavior.show_keyboard()FocusBehavior.unfocus_on_touch
- Kivy 命名空间
- ToggleButton 行为
- 触摸波纹
TouchRippleBehaviorTouchRippleBehavior.ripple_duration_inTouchRippleBehavior.ripple_duration_outTouchRippleBehavior.ripple_fade()TouchRippleBehavior.ripple_fade_from_alphaTouchRippleBehavior.ripple_fade_to_alphaTouchRippleBehavior.ripple_func_inTouchRippleBehavior.ripple_func_outTouchRippleBehavior.ripple_rad_defaultTouchRippleBehavior.ripple_scaleTouchRippleBehavior.ripple_show()
TouchRippleButtonBehavior
- RecycleView
- Viewclass 状态
RecycleViewRecycleViewBehavior- RecycleView 数据模型
- RecycleView 布局
LayoutChangeExceptionLayoutSelectionBehaviorRecycleLayoutManagerBehaviorRecycleLayoutManagerBehavior.compute_visible_views()RecycleLayoutManagerBehavior.get_view_index_at()RecycleLayoutManagerBehavior.goto_view()RecycleLayoutManagerBehavior.key_viewclassRecycleLayoutManagerBehavior.refresh_view_layout()RecycleLayoutManagerBehavior.set_visible_views()RecycleLayoutManagerBehavior.viewclass
- RecycleView 视图
RecycleDataAdapterRecycleDataAdapter.attach_recycleview()RecycleDataAdapter.create_view()RecycleDataAdapter.detach_recycleview()RecycleDataAdapter.get_view()RecycleDataAdapter.get_visible_view()RecycleDataAdapter.invalidate()RecycleDataAdapter.make_view_dirty()RecycleDataAdapter.make_views_dirty()RecycleDataAdapter.recycleviewRecycleDataAdapter.refresh_view_attrs()RecycleDataAdapter.refresh_view_layout()RecycleDataAdapter.set_visible_views()
RecycleDataViewBehaviorRecycleKVIDsDataViewBehavior
- 手风琴
- 简单示例
- 自定义手风琴组件。
AccordionAccordionExceptionAccordionItemAccordionItem.accordionAccordionItem.add_widget()AccordionItem.background_disabled_normalAccordionItem.background_disabled_selectedAccordionItem.background_normalAccordionItem.background_selectedAccordionItem.collapseAccordionItem.collapse_alphaAccordionItem.containerAccordionItem.container_titleAccordionItem.content_sizeAccordionItem.min_spaceAccordionItem.on_touch_down()AccordionItem.orientationAccordionItem.remove_widget()AccordionItem.titleAccordionItem.title_argsAccordionItem.title_template
- 操作栏
- 锚点布局
- 盒布局
- 气泡
- 按钮
- 相机
- 轮播图
CarouselCarousel.add_widget()Carousel.anim_cancel_durationCarousel.anim_move_durationCarousel.anim_typeCarousel.clear_widgets()Carousel.current_slideCarousel.directionCarousel.ignore_perpendicular_swipesCarousel.indexCarousel.load_next()Carousel.load_previous()Carousel.load_slide()Carousel.loopCarousel.min_moveCarousel.next_slideCarousel.on_touch_down()Carousel.on_touch_move()Carousel.on_touch_up()Carousel.previous_slideCarousel.remove_widget()Carousel.scroll_distanceCarousel.scroll_timeoutCarousel.slides
- 复选框
CheckBoxCheckBox.activeCheckBox.background_checkbox_disabled_downCheckBox.background_checkbox_disabled_normalCheckBox.background_checkbox_downCheckBox.background_checkbox_normalCheckBox.background_radio_disabled_downCheckBox.background_radio_disabled_normalCheckBox.background_radio_downCheckBox.background_radio_normalCheckBox.color
- 请输入需要翻译的代码内容。
- 颜色选择器
- 下拉列表
- 基本示例
- 在Kv中扩展下拉菜单
DropDownDropDown.add_widget()DropDown.attach_toDropDown.auto_dismissDropDown.auto_widthDropDown.clear_widgets()DropDown.containerDropDown.dismiss()DropDown.dismiss_on_selectDropDown.max_heightDropDown.min_state_timeDropDown.on_motion()DropDown.on_touch_down()DropDown.on_touch_move()DropDown.on_touch_up()DropDown.open()DropDown.remove_widget()DropDown.select()
- 效果部件
- 文件选择器
- 简单控件
- 控件组合
- 使用示例
FileChooserFileChooserControllerFileChooserController.cancel()FileChooserController.dirselectFileChooserController.entry_released()FileChooserController.entry_touched()FileChooserController.file_encodingsFileChooserController.file_systemFileChooserController.filesFileChooserController.filter_dirsFileChooserController.filtersFileChooserController.font_nameFileChooserController.get_nice_size()FileChooserController.layoutFileChooserController.multiselectFileChooserController.on_touch_down()FileChooserController.on_touch_up()FileChooserController.pathFileChooserController.progress_clsFileChooserController.rootpathFileChooserController.selectionFileChooserController.show_hiddenFileChooserController.sort_func
FileChooserIconLayoutFileChooserIconViewFileChooserListLayoutFileChooserListViewFileChooserProgressBaseFileSystemAbstractFileSystemLocal
- 浮动布局
- 手势表面
- 网格布局
- 背景
- 列宽与行高
- 使用GridLayout
GridLayoutGridLayout.col_default_widthGridLayout.col_force_defaultGridLayout.colsGridLayout.cols_minimumGridLayout.do_layout()GridLayout.minimum_heightGridLayout.minimum_sizeGridLayout.minimum_widthGridLayout.orientationGridLayout.paddingGridLayout.row_default_heightGridLayout.row_force_defaultGridLayout.rowsGridLayout.rows_minimumGridLayout.spacing
GridLayoutException
- 图像
- 标签
- 尺寸设置与文本内容
- 文本对齐与换行
- 标记文本
- 文本中的交互区域
- 支持Unicode语言
- 使用示例
LabelLabel.anchorsLabel.base_directionLabel.boldLabel.colorLabel.disabled_colorLabel.disabled_outline_colorLabel.ellipsis_optionsLabel.font_blendedLabel.font_contextLabel.font_directionLabel.font_familyLabel.font_featuresLabel.font_hintingLabel.font_kerningLabel.font_nameLabel.font_script_nameLabel.font_sizeLabel.halignLabel.is_shortenedLabel.italicLabel.limit_render_to_text_bboxLabel.line_heightLabel.markupLabel.max_linesLabel.mipmapLabel.on_touch_down()Label.outline_colorLabel.outline_widthLabel.paddingLabel.padding_xLabel.padding_yLabel.refsLabel.shortenLabel.shorten_fromLabel.split_strLabel.strikethroughLabel.stripLabel.textLabel.text_languageLabel.text_sizeLabel.textureLabel.texture_sizeLabel.texture_update()Label.underlineLabel.unicode_errorsLabel.valign
- 布局
- 模态视图
- 示例
- ModalView 事件
ModalViewModalView.attach_toModalView.auto_dismissModalView.backgroundModalView.background_colorModalView.borderModalView.dismiss()ModalView.on__anim_alpha()ModalView.on_dismiss()ModalView.on_motion()ModalView.on_open()ModalView.on_pre_dismiss()ModalView.on_pre_open()ModalView.on_touch_down()ModalView.on_touch_move()ModalView.on_touch_up()ModalView.open()ModalView.overlay_color
- PageLayout
- 弹出窗口
- 进度条
- RecycleBoxLayout
- RecycleGridLayout
- 回收布局
RecycleLayoutRecycleLayout.default_heightRecycleLayout.default_pos_hintRecycleLayout.default_sizeRecycleLayout.default_size_hintRecycleLayout.default_size_hint_maxRecycleLayout.default_size_hint_minRecycleLayout.default_size_hint_xRecycleLayout.default_size_hint_x_maxRecycleLayout.default_size_hint_x_minRecycleLayout.default_size_hint_yRecycleLayout.default_size_hint_y_maxRecycleLayout.default_size_hint_y_minRecycleLayout.default_widthRecycleLayout.do_layout()RecycleLayout.initial_heightRecycleLayout.initial_sizeRecycleLayout.initial_widthRecycleLayout.key_pos_hintRecycleLayout.key_sizeRecycleLayout.key_size_hintRecycleLayout.key_size_hint_maxRecycleLayout.key_size_hint_minRecycleLayout.refresh_view_layout()RecycleLayout.set_visible_views()
- 相对布局
- reStructuredText 渲染器
- 与Text一起使用
- 使用源代码
RstDocumentRstDocument.background_colorRstDocument.base_font_sizeRstDocument.colorsRstDocument.document_rootRstDocument.goto()RstDocument.preload()RstDocument.render()RstDocument.resolve_path()RstDocument.show_errorsRstDocument.sourceRstDocument.source_encodingRstDocument.source_errorRstDocument.textRstDocument.titleRstDocument.toctreesRstDocument.underline_color
- 沙盒
- 平移/缩放控件
- 用法
- 控件交互
- 自动置顶
- 缩放限制
- 行为
ScatterScatter.apply_transform()Scatter.auto_bring_to_frontScatter.bboxScatter.centerScatter.center_xScatter.center_yScatter.collide_point()Scatter.do_collide_after_childrenScatter.do_rotationScatter.do_scaleScatter.do_translationScatter.do_translation_xScatter.do_translation_yScatter.on_bring_to_front()Scatter.on_motion()Scatter.on_touch_down()Scatter.on_touch_move()Scatter.on_touch_up()Scatter.on_transform_with_touch()Scatter.posScatter.rightScatter.rotationScatter.scaleScatter.scale_maxScatter.scale_minScatter.to_local()Scatter.to_parent()Scatter.topScatter.transformScatter.transform_invScatter.translation_touchesScatter.xScatter.y
ScatterPlane
- 散射布局
- 屏幕管理器
- 基本用法
- 改变方向
- 高级用法
- 更改过渡效果。
CardTransitionFadeTransitionFallOutTransitionNoTransitionRiseInTransitionScreenScreenManagerScreenManager.add_widget()ScreenManager.clear_widgets()ScreenManager.currentScreenManager.current_screenScreenManager.get_screen()ScreenManager.has_screen()ScreenManager.next()ScreenManager.on_motion()ScreenManager.on_touch_down()ScreenManager.on_touch_move()ScreenManager.on_touch_up()ScreenManager.previous()ScreenManager.remove_widget()ScreenManager.screen_namesScreenManager.screensScreenManager.switch_to()ScreenManager.transition
ScreenManagerExceptionShaderTransitionSlideTransitionSwapTransitionTransitionBaseWipeTransition
- 滚动视图
- 滚动行为
- 限制在X轴或Y轴
- 管理内容大小与位置
- 滚动过界效果
ScrollViewScrollView.add_widget()ScrollView.always_overscrollScrollView.bar_colorScrollView.bar_inactive_colorScrollView.bar_marginScrollView.bar_posScrollView.bar_pos_xScrollView.bar_pos_yScrollView.bar_widthScrollView.convert_distance_to_scroll()ScrollView.do_scrollScrollView.do_scroll_xScrollView.do_scroll_yScrollView.effect_clsScrollView.effect_xScrollView.effect_yScrollView.hbarScrollView.on_motion()ScrollView.on_touch_down()ScrollView.on_touch_move()ScrollView.on_touch_up()ScrollView.remove_widget()ScrollView.scroll_distanceScrollView.scroll_timeoutScrollView.scroll_to()ScrollView.scroll_typeScrollView.scroll_wheel_distanceScrollView.scroll_xScrollView.scroll_yScrollView.smooth_scroll_endScrollView.to_local()ScrollView.to_parent()ScrollView.update_from_scroll()ScrollView.vbarScrollView.viewport_size
- 设置
- 滑块
SliderSlider.background_disabled_horizontalSlider.background_disabled_verticalSlider.background_horizontalSlider.background_verticalSlider.background_widthSlider.border_horizontalSlider.border_verticalSlider.cursor_disabled_imageSlider.cursor_heightSlider.cursor_imageSlider.cursor_sizeSlider.cursor_widthSlider.maxSlider.minSlider.on_touch_down()Slider.on_touch_move()Slider.on_touch_up()Slider.orientationSlider.paddingSlider.rangeSlider.sensitivitySlider.stepSlider.valueSlider.value_normalizedSlider.value_posSlider.value_trackSlider.value_track_colorSlider.value_track_width
- Spinner(下拉选择器)
- 分割器
- 堆叠布局
- 模板视图
- 开关
- 选项卡面板
- 简单示例
- 自定义选项卡面板
StripLayoutTabbedPanelTabbedPanel.add_widget()TabbedPanel.background_colorTabbedPanel.background_disabled_imageTabbedPanel.background_imageTabbedPanel.bar_widthTabbedPanel.borderTabbedPanel.clear_widgets()TabbedPanel.contentTabbedPanel.current_tabTabbedPanel.default_tabTabbedPanel.default_tab_clsTabbedPanel.default_tab_contentTabbedPanel.default_tab_textTabbedPanel.do_default_tabTabbedPanel.remove_widget()TabbedPanel.scroll_typeTabbedPanel.strip_borderTabbedPanel.strip_imageTabbedPanel.switch_to()TabbedPanel.tab_heightTabbedPanel.tab_listTabbedPanel.tab_posTabbedPanel.tab_width
TabbedPanelContentTabbedPanelExceptionTabbedPanelHeaderTabbedPanelItemTabbedPanelStrip
- 文本输入
- 使用示例
- 选择
- 处理。
- 过滤
- 默认快捷键
TextInputTextInput.allow_copyTextInput.auto_indentTextInput.background_activeTextInput.background_colorTextInput.background_disabled_normalTextInput.background_normalTextInput.base_directionTextInput.borderTextInput.cancel_selection()TextInput.copy()TextInput.cursorTextInput.cursor_blinkTextInput.cursor_colTextInput.cursor_colorTextInput.cursor_index()TextInput.cursor_offset()TextInput.cursor_posTextInput.cursor_rowTextInput.cursor_widthTextInput.cut()TextInput.delete_selection()TextInput.disabled_foreground_colorTextInput.do_backspace()TextInput.do_cursor_movement()TextInput.do_redo()TextInput.do_undo()TextInput.do_wrapTextInput.font_contextTextInput.font_familyTextInput.font_nameTextInput.font_sizeTextInput.foreground_colorTextInput.get_cursor_from_index()TextInput.get_cursor_from_xy()TextInput.get_max_scroll_x()TextInput.halignTextInput.handle_image_leftTextInput.handle_image_middleTextInput.handle_image_rightTextInput.hint_textTextInput.hint_text_colorTextInput.input_filterTextInput.insert_text()TextInput.keyboard_on_key_down()TextInput.keyboard_on_key_up()TextInput.line_heightTextInput.line_spacingTextInput.lines_to_scrollTextInput.minimum_heightTextInput.multilineTextInput.on_cursor()TextInput.on_cursor_blink()TextInput.on_double_tap()TextInput.on_quad_touch()TextInput.on_touch_down()TextInput.on_touch_move()TextInput.on_touch_up()TextInput.on_triple_tap()TextInput.paddingTextInput.padding_xTextInput.padding_yTextInput.passwordTextInput.password_maskTextInput.paste()TextInput.pgmove_speedTextInput.readonlyTextInput.replace_crlfTextInput.reset_undo()TextInput.scroll_distanceTextInput.scroll_from_swipeTextInput.scroll_timeoutTextInput.scroll_xTextInput.scroll_yTextInput.select_all()TextInput.select_text()TextInput.selection_colorTextInput.selection_fromTextInput.selection_textTextInput.selection_toTextInput.tab_widthTextInput.textTextInput.text_languageTextInput.text_validate_unfocusTextInput.use_bubbleTextInput.use_handlesTextInput.write_tab
- 切换按钮
- 树视图
- 介绍
- 创建你自己的节点部件
TreeViewTreeView.add_node()TreeView.deselect_node()TreeView.get_node_at_pos()TreeView.hide_rootTreeView.indent_levelTreeView.indent_startTreeView.iterate_all_nodes()TreeView.iterate_open_nodes()TreeView.load_funcTreeView.minimum_heightTreeView.minimum_sizeTreeView.minimum_widthTreeView.on_touch_down()TreeView.remove_node()TreeView.rootTreeView.root_optionsTreeView.select_node()TreeView.selected_nodeTreeView.toggle_node()
TreeViewExceptionTreeViewLabelTreeViewNode
- 视频
- 视频播放器
- 注释
- 全屏
- 流结束行为
VideoPlayerVideoPlayer.allow_fullscreenVideoPlayer.annotationsVideoPlayer.durationVideoPlayer.fullscreenVideoPlayer.image_loadingVideoPlayer.image_overlay_playVideoPlayer.image_pauseVideoPlayer.image_playVideoPlayer.image_stopVideoPlayer.image_volumehighVideoPlayer.image_volumelowVideoPlayer.image_volumemediumVideoPlayer.image_volumemutedVideoPlayer.on_touch_down()VideoPlayer.optionsVideoPlayer.playVideoPlayer.positionVideoPlayer.seek()VideoPlayer.sourceVideoPlayer.stateVideoPlayer.thumbnailVideoPlayer.volume
VideoPlayerAnnotation
- 虚拟键盘
- 模式
- 布局
- 请求键盘
VKeyboardVKeyboard.available_layoutsVKeyboard.backgroundVKeyboard.background_borderVKeyboard.background_colorVKeyboard.background_disabledVKeyboard.callbackVKeyboard.collide_margin()VKeyboard.dockedVKeyboard.font_sizeVKeyboard.key_background_colorVKeyboard.key_background_downVKeyboard.key_background_normalVKeyboard.key_borderVKeyboard.key_disabled_background_normalVKeyboard.key_marginVKeyboard.layoutVKeyboard.layout_pathVKeyboard.margin_hintVKeyboard.on_touch_down()VKeyboard.on_touch_up()VKeyboard.refresh()VKeyboard.setup_mode()VKeyboard.setup_mode_dock()VKeyboard.setup_mode_free()VKeyboard.target
- Widget 类
- 使用属性
- 基本绘图
- 控件触摸事件冒泡
- 使用
Widget.center、Widget.right和Widget.top属性。 WidgetWidget.add_widget()Widget.apply_class_lang_rules()Widget.canvasWidget.centerWidget.center_xWidget.center_yWidget.childrenWidget.clear_widgets()Widget.clsWidget.collide_point()Widget.collide_widget()Widget.disabledWidget.export_as_image()Widget.export_to_png()Widget.get_parent_window()Widget.get_root_window()Widget.get_window_matrix()Widget.heightWidget.idsWidget.motion_filterWidget.on_motion()Widget.on_touch_down()Widget.on_touch_move()Widget.on_touch_up()Widget.opacityWidget.parentWidget.posWidget.pos_hintWidget.proxy_refWidget.register_for_motion_event()Widget.remove_widget()Widget.rightWidget.sizeWidget.size_hintWidget.size_hint_maxWidget.size_hint_max_xWidget.size_hint_max_yWidget.size_hint_minWidget.size_hint_min_xWidget.size_hint_min_yWidget.size_hint_xWidget.size_hint_yWidget.to_local()Widget.to_parent()Widget.to_widget()Widget.to_window()Widget.topWidget.unregister_for_motion_event()Widget.walk()Widget.walk_reverse()Widget.widthWidget.xWidget.y
WidgetException