3kstc
3kstc

Reputation: 1966

How to add an image and clock to a kv file

I am trying to implement the template of the ComicCreator GUI sample as a template for my own project. The code is easy to follow, but I want to change the toolbox.kv to look something like:

enter image description here

Q: How would I be able to append a logo, instead of the buttons currently there, and also have the current date time display (DD/MM/YYYY HH:MM) shown perpetually.And lastly add a string NYC, New York, USA, all underneath each other as in the picture.

Upvotes: 0

Views: 3665

Answers (1)

el3ien
el3ien

Reputation: 5405

Some playing arround with BoxLayout's and Image or AsyncImage if your image is from the web.

So the python code could look like this.

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
from kivy.clock import Clock
import time


class MyLayout(BoxLayout):
    your_time = StringProperty()
    def __init__(self,**kwargs):
        super(MyLayout,self).__init__(**kwargs)
        self.orientation = "vertical"
        self.padding = 10
        Clock.schedule_interval(self.set_time, 0.1)    

    def set_time(self,dt):
        self.your_time = time.strftime("%m/%d/%Y %H:%M")

class MyApp(App):
    def build(self):
        return MyLayout()


if __name__ == "__main__":
    MyApp().run()


And kv file look like this.

#:kivy 1.9.1

<MyLayout>:
    BoxLayout:
        spacing: 10
        padding: 10,10,10,0
        orientation: "horizontal"
        BoxLayout:
            orientation: "vertical"
            size_hint: 0.3,1
            canvas:
                Rectangle:
                    pos: self.pos
                    size: self.size
            AsyncImage
                source: 'http://lmsotfy.com/so.png'
            Label:
                size_hint: 1,0.3
                text: root.your_time
                color: [0,0,0,1]
            Label:
                size_hint: 1,0.3
                text: "NYC, New York, USA"
                color: [0,0,0,1]

        Button:
            text: ""

    BoxLayout:
        padding: 10,10,10,0
        spacing: 10
        size_hint: 1,0.3
        orientation: "horizontal"
        Button:
            text: "Clear"
        Button:
            text: "Remove"
        Button:
            text: "Group"
        Button:
            text: "Color"
        Button:
            text: "Gestures"

    BoxLayout:
        padding: 10,10,10,10
        size_hint: 1,0.3
        Button:
            text: "Total figures: 1          Kivy Started"


This will look like this:

kivy app

Upvotes: 1

Related Questions