kivy 两个按键之间隔开距离,kv file 怎么写

 如上图, 简单的两个按键如何在kivy中实现?

用boxlayout无法实现,最后决定用stacklayout.

kv 源代码如下:

        StackLayout:

            orientation:'rl-bt'

            padding:10

            spacing:10

            MDFlatButton:

                text: "取消"

                font_name:'ms'

                md_bg_color: app.theme_cls.primary_color

                theme_text_color:"Primary"

                #padding:10,10

            MDFlatButton:

                text: "确定"

                font_name:'ms'

                md_bg_color: app.theme_cls.primary_color

                theme_text_color:"Primary"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的记账应用程序,使用Python和Kivy构建。该应用程序包括一个主界面,用于显示支出和收入的列表,以及一个添加支出和收入的表单。 首先,需要安装kivy: ``` pip install kivy ``` 然后,创建一个名为main.py的文件,并添加以下代码: ```python from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.properties import ObjectProperty from kivy.uix.popup import Popup from kivy.uix.label import Label from kivy.uix.button import Button from kivy.uix.textinput import TextInput from kivy.uix.scrollview import ScrollView class Transaction: def __init__(self, name, amount, transaction_type): self.name = name self.amount = amount self.transaction_type = transaction_type class MainScreen(BoxLayout): transactions_list = ObjectProperty(None) amount_input = ObjectProperty(None) name_input = ObjectProperty(None) def __init__(self, **kwargs): super(MainScreen, self).__init__(**kwargs) self.transactions = [] def add_transaction(self, transaction_type): name = self.name_input.text amount = self.amount_input.text if name == '' or amount == '': popup = Popup(title='Error', content=Label(text='Please fill in all fields'), size_hint=(None, None), size=(200, 200)) popup.open() return try: amount = float(amount) except ValueError: popup = Popup(title='Error', content=Label(text='Amount must be a number'), size_hint=(None, None), size=(200, 200)) popup.open() return if transaction_type == 'income': self.transactions.append(Transaction(name, amount, 'Income')) else: self.transactions.append(Transaction(name, amount, 'Expense')) self.transactions_list.add_widget(Label(text=name)) self.transactions_list.add_widget(Label(text=str(amount))) def clear_inputs(self): self.name_input.text = '' self.amount_input.text = '' class MyApp(App): def build(self): return MainScreen() if __name__ == '__main__': MyApp().run() ``` 这个应用程序包括一个Transaction类,用于表示一个收入或支出事务。主屏幕类包括一个transactions列表,用于跟踪所有添加的交易。add_transaction方法用于将新的交易添加到列表,并将其显示在主屏幕上。 现在,创建一个名为main.kv的文件,并添加以下代码: ```kivy <MainScreen>: orientation: 'vertical' BoxLayout: orientation: 'horizontal' Label: text: 'Name' TextInput: id: name_input Label: text: 'Amount' TextInput: id: amount_input BoxLayout: orientation: 'horizontal' Button: text: 'Add Income' on_release: root.add_transaction('income') Button: text: 'Add Expense' on_release: root.add_transaction('expense') Button: text: 'Clear' on_release: root.clear_inputs() ScrollView: size_hint: 1, 1 BoxLayout: id: transactions_list orientation: 'vertical' ``` 这个文件定义了主屏幕的布局。它包括一个用于输入事务信息的表单,一个用于添加新事务的按钮组,以及一个用于显示所有事务的滚动视图。 现在,执行以下命令来启动应用程序: ``` python main.py ``` 这将启动应用程序,并在屏幕上显示一个空的事务列表。使用表单和按钮添加一些收入和支出,然后查看列表。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值