Calling a Kivy application from another Kivy application

766 views
Skip to first unread message

Gee

unread,
Sep 18, 2014, 12:33:22 AM9/18/14
to kivy-...@googlegroups.com
Hello,
Is it possible to execute one Kivy application from another Kivy one?
I was trying to execute hello.py within test.py (please see below) using execfile().
The hello.py works fine from Python interactive console.
When test.py is executed the Kivy window opens okay but when the "Connect" button is pressed (i.e execfile() is called) I get errors.

I must be doing some basic conceptual mistake.

Any suggestion/help would be much appreciated.

Error message

    File "test.py", line 20, in fn
     execfile("hello.py")
   File "hello.py", line 12, in <module>
     HelloApp().run()
   File "/usr/lib/python2.7/site-packages/Kivy-1.8.0-py2.7-linux-x86_64.egg/kivy/app.py", line 766, in run
     root = self.build()
   File "hello.py", line 9, in build
     return Label(text="Hello World!")
 NameError: global name 'Label' is not defined


test.py

import kivy
kivy.require('1.7.0')
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout

class CombWidget(FloatLayout):
    def __init__(self, **kwargs):
        super(CombWidget, self).__init__(**kwargs)
        b1 = Button(text="Connect", font_size = 12,
               pos_hint={'center_x':.5, 'center_y':.5}, size_hint=(0.2, 0.1))
        b1.bind(on_press = self.fn)
        self.add_widget (b1)
   
    def fn(self, value):
        execfile("hello.py")    
   
class TestApp(App):
    def build(self):
        print ("Building screen")
        return CombWidget(size_hint = (1,1), width = 800, cols = 1)
if __name__ == "__main__":
     TestApp().run()

hello.py
import kivy
kivy.require('1.7.0')
from kivy.app import App
from kivy.uix.button import Label

class HelloApp(App):
    def build(self):
        return Label(text="Hello World!")

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










Message has been deleted

Felipe França

unread,
Sep 18, 2014, 9:02:03 AM9/18/14
to kivy-...@googlegroups.com
Hi Gee,
I tested your example, and if you put:
from kivy.uix.button import Label
in test.py file, the error will be solved, but in your screen, the label will override the button.

Bill Janssen

unread,
Sep 18, 2014, 4:05:40 PM9/18/14
to kivy-...@googlegroups.com
Try "from kivy.uix.label import Label" instead of "from kivy.uix.button import Label".

Bill

Gee

unread,
Sep 18, 2014, 7:42:07 PM9/18/14
to kivy-...@googlegroups.com
Thank you Felipe and Bill for your reply. Yes, it removes the error but overrides the label. I needed to open the second application (hello.py) in a separate window which I am looking at now. 

Alexander Taylor

unread,
Sep 19, 2014, 5:40:38 AM9/19/14
to kivy-...@googlegroups.com
You can't just run execfile to do this, the App classes cannot simultaneously run. I guess you could try using subprocess to make a whole new kivy process.

Gee

unread,
Sep 21, 2014, 9:00:25 PM9/21/14
to kivy-...@googlegroups.com
That's right Alexander. I have now found Screen Manger which works fine for my case. Basically I wanted to have one window first, and then move to another.
Thank you for your response. 
Reply all
Reply to author
Forward
0 new messages