python中的display_Python Kivy中的Display属性

参考您的kv文件:

在计算千伏在display: entry

在主.py在

^{pr2}$

display是您的变量,它被声明为KivyObjectProperty。它用于引用kv文件中实例化的TextInput子控件。在声明一个ObjectProperty之后,您将它连接到在kv文件中创建的子小部件,例如display: entry。完成后,您可以轻松地引用calculate方法中的TextInput属性。在

示例

在主.py在from kivy.app import App

from kivy.uix.gridlayout import GridLayout

from kivy.properties import ObjectProperty

class CalcGridLayout(GridLayout):

display = ObjectProperty(None)

def calculate(self, dt):

print(self.display.text)

class CalcApp(App):

def build(self):

return CalcGridLayout()

if __name__ == '__main__':

CalcApp().run()

在计算千伏在#:kivy 1.10.0

:

id: calculator

display: entry #this is the display property

rows: 5

padding: 10

spacing: 10

BoxLayout:

TextInput:

id: entry #with the value of this

font_size: 32

multiline: False

BoxLayout:

spacing: 10

Button:

text: "7"

on_press: entry.text += self.text

Button:

text: "8"

on_press: entry.text += self.text

Button:

text: "9"

on_press: entry.text += self.text

Button:

text: "+"

on_press: entry.text += self.text

BoxLayout:

spacing: 10

Button:

text: "4"

on_press: entry.text += self.text

Button:

text: "5"

on_press: entry.text += self.text

Button:

text: "6"

on_press: entry.text += self.text

Button:

text: "-"

on_press: entry.text += self.text

BoxLayout:

spacing: 10

Button:

text: "1"

on_press: entry.text += self.text

Button:

text: "2"

on_press: entry.text += self.text

Button:

text: "3"

on_press: entry.text += self.text

Button:

text: "*"

on_press: entry.text += self.text

BoxLayout:

spacing: 10

Button:

text: "AC"

on_press: entry.text = ""

Button:

text: "0"

on_press: entry.text += self.text

Button:

text: "="

on_press: calculator.calculate(entry.text)

Button:

text: "/"

on_press: entry.text += self.text

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值