[Kivy] Program ending unexpectedly without output - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Kivy] Program ending unexpectedly without output (/thread-13969.html) |
Program ending unexpectedly without output - test - Nov-09-2018 Hello! I just started learning to use kivy. I copied an example from the docs into nano, but it doesn't show any output and terminates on its own. Here is the code: import kivy kivy.require ('1.10.1') from kivy.app import App from kivy.uix.label import Label from kivy.uix.gridlayout import GridLayout from kivy.uix.textinput import TextInput class Login(GridLayout): def __init__(self, **kwargs): super(Login, self).__init__(**kwargs) self.cols = 2 self.add_widget(Label(text='Username')) self.username = TextInput(multiline=False) self.add_widget(self.username) self.add_widget(Label(text='Password')) self.password = TextInput(multiline=False, password=True) self.add_widget(self.password) class MyApp(App): def build(self): return Login() # return Label(text='Hello world!') if __name__ == '__main__': MyApp().run()the output in the console is the following: where am i making the mistake??
RE: Program ending unexpectedly without output - j.crater - Nov-09-2018 Have you followed the installation instructions closesly? Especially point #2, if you are using Windows. RE: Program ending unexpectedly without output - test - Nov-11-2018 Sorry for a bad post. I made a mistake while typing code out. Here is the working code. Thank you :) from kivy.app import App from kivy.uix.widget import Widget from kivy.uix.button import Button from kivy.uix.boxlayout import BoxLayout from kivy.properties import ListProperty class RootWidget(BoxLayout): def __init__ (self, **kwargs): super(RootWidget, self).__init__ ( **kwargs) self.add_widget(Button(text='btn 1')) cb = CustomBtn() cb.bind(pressed=self.btn_pressed) self.add_widget(cb) self.add_widget(Button(text='btn 2')) def btn_pressed(self, instance, pos): print ('pos: printed from root widget {pos}'.format(pos=pos)) class CustomBtn(Widget): pressed = ListProperty([0, 0]) def on_touch_down(self, touch): if self.collide_point( *touch.pos): self.pressed = touch.pos # we consumed the touch. return False here to propagate # the touch further to the children. return True return super(CustomBtn, self).on_touch_down(touch) def on_pressed(self, instance, pos): print ('pressed at {pos}'.format(pos=pos)) class TestApp(App): def build(self): return RootWidget() if __name__ == '__main__': TestApp().run() |