Kivy Flashcards

1
Q

Create a simple Hello World app

A

Replace this with your

import kivy
from kivy.app import App
from kivy.uix.label import Label

# current version
kivy.require(‘1.11.1’)

class MyFirstKivyApp(App):

# Function that returns  
# the root widget 
def build(self): 
      
    # Label with text Hello World is  
    # returned as root widget 
    return Label(text ="Hello World !")           

# and its run() method is called.
# This initializes and starts
# our Kivy application.
MyFirstKivyApp().run()

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

Create a label that is 20sp in size and whatever color you want?

A

l2 = Label(text=”this and that”, font_size=’20sp’, color=(0.41, 0.42, 0.74, 1))

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

How would you use markup to decorate your label to be a certain color and bold that’s 20sp in size

A

l2 = Label(text =”[color = ff3333][b]’Label’[/b] is Added [/color]\n
[color = 3333ff]Screen !!:):):):)[/color]”,
font_size =’20sp’, markup = True)

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

What are the markup tags?

A

[b][/b] -> Activate bold text
[i][/i] -> Activate italic text
[u][/u] -> Underlined text
[s][/s] -> Strikethrough text
[font=][/font] -> Change the font
[size=][/size]] -> Change the font size
[color=#][/color] -> Change the text color
[ref=][/ref] -> Add an interactive zone. The reference + bounding box inside the reference will be available in Label.refs
[anchor=] -> Put an anchor in the text. You can get the position of your anchor within the text with Label.anchors
[sub][/sub] -> Display the text at a subscript position relative to the text before it.
[sup][/sup] -> Display the text at a superscript position relative to the text before it.

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

How would you create a text input widget?

A

import kivy module

Program to Show how to use textinput (UX widget) in kivy

import kivy

# app:always refers to the instance of your application
from kivy.app import App

# below this kivy version you cannot
# use the app or software
kivy.require(‘1.9.0’)

from kivy.uix.label import Label

# to work with FloatLayout first
# you have to import it
from kivy.uix.floatlayout import FloatLayout

# widgets that can be translated,
# rotated and scaled with two or more
# fingers on a multitouch system.
from kivy.uix.scatter import Scatter

# box for editable plain text
from kivy.uix.textinput import TextInput

# in vertical fashion that
# is one on top of another or in
# horizontal fashion that is one after another.
from kivy.uix.boxlayout import BoxLayout

class TutorialApp(App):

def build(self): 
  
    b = BoxLayout(orientation ='vertical') 
  
    # Adding the text input 
    t = TextInput(font_size = 50, 
                  size_hint_y = None, 
                  height = 100) 
      
    f = FloatLayout() 
  
    # By this you are able to move the 
    # Text on the screen to anywhere you want 
    s = Scatter() 
  
    l = Label(text ="Hello !", 
              font_size = 50) 
  
    f.add_widget(s) 
    s.add_widget(l) 
  
    b.add_widget(t) 
    b.add_widget(f) 
  
    # Binding it with the label 
    t.bind(text = l.setter('text')) 
  
      
    return b 

if __name__ == “__main__”:
TutorialApp().run()

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

What is the command for a box layout?

A

BoxLayout(orientation = ‘vertical’)

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

What is used to create a textinput with the font being size 50, size_hint_y being none and height being 100

A

TextInput(font_size = 50,
size_hint_y = None,
height = 100)

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