• throwaway4

    I'm trying to implement a long button press and record the elapsed time. Similar to how you can implement the touch_began and touch_ended methods for a ui.View, is it possible to do this for buttons?
    I noticed that if I create a view with a button that is touch-enabled, I can tap the screen to record a touch for any location EXCEPT the button.

    Is there a simple way to do the same with buttons?

    My code so far:

    from datetime import datetime as dt
    import ui
    class Touch_Test(ui.View):
       def __init__(self):
          self.background_color = 'white'
          self.button = ui.Button(title='Button', frame=(100,100,100,30), action=self.get_touch)
       def touch_began(self, touch):
          self.press_time = dt.now()
          print('Pressed {}'.format(touch.location))
       def touch_ended(self, touch):
          self.press_time_elapsed = dt.now() - self.press_time
          print('Time Elapsed: {}'.format(self.press_time_elapsed))
       def get_touch(self, sender):
          print('Pressed Button {}'.format(sender)
    if __name__ == '__main__':
       t = Touch_Test()

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!