android - Display property in Python Kivy -
i have been watching tutorial kivy , python creating calculator, i've seen property: display value of widget id. value can access other properties of widget. here code (.kv file):
<calcgridlayout>: id: calculator display: entry #this display property rows: 5 padding: 10 spacing: 10 boxlayout: textinput: id: entry #with value of 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
what variable/property? used for?
with reference kv file:
calc.kv
display: entry
main.py
display = objectproperty(none)
display - variable , declared python object, objectproperty. used reference textinput child widget created kv rule. after declaring objectproperty, hook child widget created in kv rule e.g. "display: entry". once that's done, can reference textinput property inside calculate method.
example
main.py
from kivy.app import app kivy.uix.gridlayout import gridlayout 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()
calc.kv
#:kivy 1.10.0 <calcgridlayout>: id: calculator display: entry #this display property rows: 5 padding: 10 spacing: 10 boxlayout: textinput: id: entry #with value of 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
wiki
Comments
Post a Comment