Python Kivy中的进度栏​​小部件

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

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

进度栏小部件:

ProgressBar小部件用于可视化某些任务的进度。当前仅支持水平模式:垂直模式尚不可用。

进度栏没有交互元素, 并且是仅用于显示的窗口小部件。

要使用它, 只需分配一个值以指示当前进度:

from kivy.uix.progressbar import ProgressBar
pb = ProgressBar( max = 1000 )
 
# this will update the graphics automatically (75 % done)
pb.value = 750

要使用Progressbar小部件, 你必须通过以下命令将其导入:从kivy.uix.progressbar import ProgressBar

妓女的酒吧接受两个参数:

1)最大值:允许的最大值。它是一个数值属性, 默认为100。

2)值:滑块的当前值

Basic Approach:

1) import kivy
2) import kivyApp
3) import progressbar
4) import Boxlayout(according to need)
5) Set minimum version(optional)
6) Create Layout class:
7) Create App class
8) return Layout/widget/Class(according to requirement)
9) Run an instance of the class

注意:

该代码用于完整的进度条, 你只需要专注于进度条的创建和工作即可, 而无需强调其他属性, 我将在以后介绍它们。

你首先必须单击文件中的按钮, 然后进度条将显示。

该方法的实施:

# Program to Show how to create a Progressbar in .kv file
 
# 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' )
   
# The ProgressBar widget is used to
# visualize the progress of some task
from kivy.uix.progressbar import ProgressBar
 
# BoxLayout arranges children in a vertical or horizontal box.
# or help to put the children at the desired location.
from kivy.uix.boxlayout import BoxLayout
 
# The Clock object allows you to schedule a
# function call in the future
from kivy.clock import Clock
  
# The Button is a Label with associated actions
# that is triggered when the button
# is pressed (or released after a click /touch). 
from kivy.uix.button import Button
 
# Popup widget is used to create popups.
# By default, the popup will cover
# the whole "parent" window.
# When you are creating a popup, # you must at least set a Popup.title and Popup.content.
from kivy.uix.popup import Popup
 
# A Widget is the base building block
# of GUI interfaces in Kivy.
# It provides a Canvas that
# can be used to draw on screen.
from kivy.uix.widget import Widget
 
# ObjectProperty is a specialised sub-class
# of the Property class, so it has the same
# initialisation parameters as it:
# By default, a Property always takes a default
# value[.] The default value must be a value
# that agrees with the Property type.
from kivy.properties import ObjectProperty
 
 
 
# Create the widget class
class MyWidget(Widget):
 
     progress_bar = ObjectProperty()
     
     def __init__( self , * * kwa):
         super (MyWidget, self ).__init__( * * kwa)
         
         self .progress_bar = ProgressBar()
         self .popup = Popup(
             title = 'Download' , content = self .progress_bar
         )
         self .popup.bind(on_open = self .puopen)
         self .add_widget(Button(text = 'Download' , on_release = self .pop))
 
     # the function which works when you clicj = k the button
     def pop( self , instance):
         self .progress_bar.value = 1
         self .popup. open ()
 
     # To continuesly increasing the value of pb.
     def next ( self , dt):
         if self .progress_bar.value> = 100 :
             return False
         self .progress_bar.value + = 1
     
     def puopen( self , instance):
         Clock.schedule_interval( self . next , 1 /25 )
 
# Create the App class
class MyApp(App):
     def build( self ):
         return MyWidget()
 
# run the App
if __name__ in ( "__main__" ):
     MyApp().run()

输出如下:

图片1

Python Kivy中的进度栏​​小部件1

图片2:

Python Kivy中的进度栏​​小部件2

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


来源:

https://www.srcmini02.com/70101.html

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?