个性化阅读
专注于IT技术分析

Python Kivy中的选项卡式面板

Kivy是Python中与平台无关的GUI工具。由于它可以在Android, IOS, Linux和Windows等操作系统上运行。它基本上是用于开发Android应用程序, 但这并不意味着它不能在桌面应用程序上使用。

??Kivy教程–通过示例学习Kivy。

选项卡式面板

TabbedPanel窗口小部件管理选项卡中的不同窗口小部件, 具有用于实际选项卡按钮的标题区域和用于显示当前选项卡内容的内容区域。

TabbedPanel提供了一个默认选项卡。

要使用它, 必须import:from kivy.uix.tabbedpanel import TabbedPanel

Basic Approach:
1) import kivy
2) import kivy App
3) import floatlayout
4) import tabbedpanel
5) set minimum version(optional)
6) Create Tabbed panel class
7) create the App class
8) create .kv file:
       # create multiple tabs in it.
       # Do there functioninging also.
9) return the widget/layout etc class
10) Run an instance of the class

实施方法:

.py文件

# Program to explain how to create tabbed panel App in kivy  
       
# import kivy module     
import kivy   
         
# base Class of your App inherits from the App class.     
# app:always refers to the instance of your application    
from kivy.app import App  
       
# this restrict the kivy version i.e   
# below this kivy version you cannot   
# use the app or software   
kivy.require( '1.9.0' )  
  
# to  use this must have to import it
from kivy.uix.tabbedpanel import TabbedPanel
  
# Floatlayout allows us to place the elements
# relatively based on the current window
# size and height especially in mobiles
from kivy.uix.floatlayout import FloatLayout
  
# Create Tabbed class 
class Tab(TabbedPanel):
     pass
   
# create App class
class TabbedPanelApp(App):
     def build( self ):
         return Tab()
  
# run the App
if __name__ = = '__main__' :
     TabbedPanelApp().run()

.kv文件

# .kv file of tabbed panel
  
<Tab>:
  
     # creating the size
     # and the alignment of the tab 
     size_hint: . 5 , . 5
     pos_hint: { 'center_x' : . 5 , 'center_y' : . 5 }
     do_default_tab: False
  
     # Create tab 1
     TabbedPanelItem:
         text: 'Tab 1'
         Label:
             text: "First tab"
  
     # Create 2nd tab
     TabbedPanelItem:
         text: 'Tab 2'
         BoxLayout:
             Label:
                 text: 'Press button'
             Button:
                 text: 'Click it'
  
     # Create 3rd tab
     TabbedPanelItem:
         text: 'Tab 3'
         RstDocument:
             text: '\n' .join(( "How are you GFG's???" ))

输出如下:

标签1:

Python Kivy中的选项卡式面板1

标签2:

Python Kivy中的选项卡式面板2

标签3:

Python Kivy中的选项卡式面板3

首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。


赞(0)
未经允许不得转载:srcmini » Python Kivy中的选项卡式面板

评论 抢沙发

评论前必须登录!