Code With Josh Kivy Flashcards

1
Q

Import Your app, boxlayout, textinput, buttons, gridlayout and window

A

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.core.window imporlt Window

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Create a calculator class that inherits the BoxLayout and initialize it

A

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.core.window imporlt Window

class Calculator(BoxLayout):
def __init__(self, **kwargs):
super().__init__(orientation=’vertical’, **kwargs)

class MyLabApp(App):
def build(self):
return Calculator

Need a screen manager for multiple screens

MyLabApp().run()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give your calculator the size of 300x500

A

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.core.window imporlt Window

Window.size = (300, 500)
class Calculator(BoxLayout):
def __init__(self, **kwargs):
super().__init__(orientation=’vertical’, **kwargs)

class MyLabApp(App):
def build(self):
return Calculator

Need a screen manager for multiple screens

MyLabApp().run()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Add a text input box to your main boxlayout give it
font size
a y axis size hint
make it read only
make it align to the right
it shouldn’t let you do multiline strings

A

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.core.window imporlt Window

Window.size = (300, 500)
class Calculator(BoxLayout):
def __init__(self, **kwargs):
super().__init__(orientation=’vertical’, **kwargs)

self.result = TextInput(
font_size=45,
size_hint_y=0.2 (this goes from 0-1)
readonly=True
halign=”right”
multiline=False
)

self.add_widget(self.result)

class MyLabApp(App):
def build(self):
return Calculator

Need a screen manager for multiple screens

MyLabApp().run()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Create a few buttons

A

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.core.window imporlt Window

Window.size = (300, 500)
class Calculator(BoxLayout):
def __init__(self, **kwargs):
super().__init__(orientation=’vertical’, **kwargs)

self.result = TextInput(
font_size=45,
size_hint_y=0.2 (this goes from 0-1)
readonly=True
halign=”right”
multiline=False
)

self.add_widget(self.result)

buttons = [
[‘c’, ‘+/-‘, ‘%’, ‘/’],
[‘7’, ‘8’, ‘9’, ‘*’]
]

grid = GridLayout(cols=4, spacing=5, padding=10)
for row in buttons:
for item in row:
button = Button(
text=item,
font_size=32,
grid.add_widget(button)
self.add_widget(grid)
)
class MyLabApp(App):
def build(self):
return Calculator

Need a screen manager for multiple screens

MyLabApp().run()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Make your buttons do something

A

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.core.window imporlt Window

Window.size = (300, 500)
class Calculator(BoxLayout):
def __init__(self, **kwargs):
super().__init__(orientation=’vertical’, **kwargs)

self.result = TextInput(
font_size=45,
size_hint_y=0.2 (this goes from 0-1)
readonly=True
halign=”right”
multiline=False
)

self.add_widget(self.result)

buttons = [
[‘c’, ‘+/-‘, ‘%’, ‘/’],
[‘7’, ‘8’, ‘9’, ‘*’]
]

grid = GridLayout(cols=4, spacing=5, padding=10)
for row in buttons:
for item in row:
button = Button(
text=item,
font_size=32,
on_press=self.button_click
)

grid.add_widget(button)
self.add_widget(grid)

def button_click(self, instance):
text = instance.text
if text ==”C” :
pass
elif text == “=”
pass

class MyLabApp(App):
def build(self):
return Calculator

Need a screen manager for multiple screens

MyLabApp().run()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly