Skip to content

Instantly share code, notes, and snippets.

@kengoon
Forked from tshirtman/calc.kv
Created October 12, 2020 21:02
Show Gist options
  • Save kengoon/93be1f2affbd2db576f8e92b0eee913b to your computer and use it in GitHub Desktop.
Save kengoon/93be1f2affbd2db576f8e92b0eee913b to your computer and use it in GitHub Desktop.
BoxLayout:
orientation: 'vertical'
Label:
size_hint_y: None
height: '50dp'
id: calc
text: ''
GridLayout:
cols: 4
Button:
text: '+'
on_press: calc.text += '+'
Button:
text: '-'
on_press: calc.text += '-'
Button:
text: '*'
on_press: calc.text += '*'
Button:
text: '/'
on_press: calc.text += '/'
Button:
text: '9'
on_press: calc.text += '9'
Button:
text: '8'
on_press: calc.text += '8'
Button:
text: '7'
on_press: calc.text += '7'
Button:
text: 'CE'
on_press: calc.text = ''
Button:
text: '6'
on_press: calc.text += '6'
Button:
text: '5'
on_press: calc.text += '5'
Button:
text: '4'
on_press: calc.text += '4'
# let's rowspan 2
Widget:
Button:
y: placeholder1.y
x: self.parent.x
width: self.parent.width
height: self.parent.height + placeholder1.height
text: '='
on_press: app.calc(calc)
Button:
text: '3'
on_press: calc.text += '3'
Button:
text: '2'
on_press: calc.text += '2'
Button:
text: '1'
on_press: calc.text += '1'
Widget:
id: placeholder1
# placeholder for the '=' rowspan
# let's colspan 4
Widget:
Button:
pos: self.parent.pos
height: self.parent.height
width: self.parent.width * 4
text: '0'
on_press: calc.text += '0'
from kivy.app import App
class CalcApp(App):
def calc(self, label):
try:
label.text = str(eval(label.text))
except:
label.text = 'syn error'
CalcApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment