Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kivy: Multiple items in a popup wont work

Tags:

python

popup

kivy

I am trying to use multiple items in a popup with kivy in python. I would like to find out how to make this work. I am not sure if it has to do with the fact that the script is on my phone and not made for computer. Here is a little example script that I am asking you to help make work for future reference.

import kivy
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label

popup = Popup(title='Test popup',
    content=Label(text='Hello world'),
            TextInput(text='Hi'),        #Here is what I am trying to make work
    size_hint=(None, None), size=(400, 400))

So you can see it is two objects in one content of the popup. I am sure this is possible because I've seen it on kivy apps in the appstore, but not sure how to do it myself.

like image 389
Kogan007 Avatar asked Mar 07 '14 00:03

Kogan007


1 Answers

The content of a Popup can only be a single widget. You cannot add two widgets like you're trying to do.

To accomplish what you're trying to do you'll have to add the label and text input to e.g. a boxlayout and then add the boxlayout to content. Here's an example that should work:

from kivy.uix.popup import Popup
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label

box = BoxLayout()
box.add_widget(Label(text='Hello world'))
box.add_widget(TextInput(text='Hi'))

popup = Popup(title='Test popup', content=box, size_hint=(None, None), size=(400, 400))
like image 105
Matt Avatar answered Nov 01 '22 07:11

Matt