Python Forum
[Kivy] Program ending unexpectedly without output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Kivy] Program ending unexpectedly without output
#3
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()
Reply


Messages In This Thread
RE: Program ending unexpectedly without output - by test - Nov-11-2018, 10:39 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020