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

Python在Kivy中设置背景模板示例

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

设置好的背景模板是一件好事, 可以使你的应用对用户更具吸引力。要在你的应用中插入背景模板, 需要在.kv文件中进行一些修改。以下是为你的应用设置背景模板的代码。

.py文件

# Program to create a background template for the App
  
# import necessary modules from kivy
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
  
# create a background class which inherits the boxlayout class
class Background(BoxLayout):
     def __init__( self , * * kwargs):
         super ().__init__( * * kwargs)
     pass
  
# Create App class with name of your app
class SampleApp(App):
  
# return the Window having the background template.
     def build( self ):
         return Background()
  
# run app in the main function
if __name__ = = '__main__' :
     SampleApp().run()

.kv文件

<Background>:
     id : main_win
     orientation: "vertical"
     spacing: 10
     space_x: self .size[ 0 ] /3
  
  
     canvas.before:
         Color:
             rgba: ( 1 , 1 , 1 , 1 )
         Rectangle:
             source: 'back.jfif'
             size: root.width, root.height
             pos: self .pos
     Button:
         text: "Click Me"
         pos_hint :{ 'center_x' : 0.2 , 'center_y' : 0.2 }
         size_hint: . 30 , 0
         background_color: ( 0.06 , . 36 , . 4 , . 675 )
         font_size: 40

输出如下:

Python在Kivy中设置背景模板实例

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


赞(0)
未经允许不得转载:srcmini » Python在Kivy中设置背景模板示例

评论 抢沙发

评论前必须登录!