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()