Created
February 21, 2013 10:23
-
-
Save tshirtman/5003739 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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