hacks4life
hacks4life

Reputation: 693

Creating a console in Kivy

I'm trying to write a very basic Kivy program that will use 3 different layouts to split the screen into :

So far I was thinking to use a main gridLayout, in which I use 3 different floatLayout.

Here's what the code looks like:

class Logo(App):

    def build(self):
        layout = GridLayout(rows=3)
        layoutTop = FloatLayout(size=(100,300))
        layoutMid = FloatLayout(size=(100,300))
        layoutDown = FloatLayout(size=(100,300))

        logo = Image(source='imagine.png',size_hint=(.25,.25),pos=(30,380))
        blank = Label(text='', font_size = '25sp',pos=(-200,100))
        titre = Label(text='#LeCubeMedia',font_size='40sp',pos=(0,280))
        ip = Label(text='192.168.42.1',font_size='25sp',pos=(250,280))

        layoutTop.add_widget(titre)
        layoutTop.add_widget(logo)
        layoutTop.add_widget(ip)
        layoutMid.add_widget(blank)

        layout.add_widget(layoutTop)
        layout.add_widget(layoutMid)

        return layout

if __name__ == '__main__':

    Logo().run()

Actually my problem is regarding the creation of the console. I have read a lot of the Kivy docs, but I am still looking for a good way to do this type of widget.

How do you think it would be if I send something with a Python print into my Kivy app, and then refresh as soon as I need to send something else (to erase the previous print). This way it would be a console-like. But, so far I have not much ideas..

Any ideas ?

Upvotes: 1

Views: 3484

Answers (2)

qua-non
qua-non

Reputation: 4162

This was a attempt trying stuff out with kivy, the code is old and you might need to adjust it a bit to make it run with latest kivy. Kivy-designer also includes this. This is using the simple way of using two textinputs, 1 for history and the other for input.

A better way to do a proper console would be to use pyte and draw characters directly onto the canvas of a widget. This way one would get VT emulation for free.

Upvotes: 2

brousch
brousch

Reputation: 1072

I have seen 2 types of consoles in Kivy. The first is a multiline textinput in a scrollview where you append the new text to the old in the textinput. The second is a BoxLayout or GridLayout in a Scrollview where each console output is a separate label in the layout.

Upvotes: 2

Related Questions