Advertisement
makut

Untitled

Oct 28th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.39 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. from kivy.app import App
  4. from kivy.uix.button import Button
  5. from kivy.uix.label import Label
  6. from kivy.uix.floatlayout import FloatLayout
  7. from kivy.clock import Clock
  8. import time
  9.  
  10.  
  11. START = int(time.time())
  12.  
  13. n = 0
  14.  
  15. def current_time(seconds):
  16.     return str(seconds // 60) + ' minutes ' + str(seconds % 60) + ' seconds'
  17.  
  18. def main():
  19.     global n
  20.     app = Main()
  21.     n += 1
  22.     return app
  23.  
  24. def callback(instance, value):
  25.     pass
  26.  
  27. string = "You haven't played Dota for:\n" + current_time(0)
  28. height = 550
  29. width = 350
  30.  
  31.  
  32. class TimeLabel(Label):
  33.     def update(self, *args):
  34.         self.text = "You haven't played Dota for:\n" + current_time(int(time.time()) - START)
  35.  
  36.  
  37. class Main(App):
  38.     def build(self):
  39.         global string
  40.         global height
  41.         global width
  42.         self.layout = FloatLayout(size = (width, height))
  43.         self.but1 = Button(text='Motivation', font_size=14, size_hint = (.45, .15),
  44.                            pos_hint = {'x' : 0.02857142857142857, 'y' : 0.02857142857142857})
  45.         self.but2 = Button(text='Achievements', font_size=14, size_hint = (.45, .15),
  46.                            pos_hint = {'x' : 0.5142857142857142, 'y' : 0.02857142857142857})
  47.         self.but3 = Button(text='Stats', font_size=14, size_hint = (.45, .15), pos_hint = {'x' : 0.02857142857142857,
  48.                                                                                           'y' : 0.2})
  49.         self.but4 = Button(text='Advice', font_size=14, size_hint = (.45, .15), pos_hint = {'x' : 0.5142857142857142,
  50.                                                                                            'y' : 0.2})
  51.         self.text = TimeLabel()
  52.         self.but1.bind(state=callback)
  53.         self.but2.bind(state=callback)
  54.         self.but3.bind(state=callback)
  55.         self.but4.bind(state=callback)
  56.         self.layout.add_widget(self.but1)
  57.         self.layout.add_widget(self.but2)
  58.         self.layout.add_widget(self.but3)
  59.         self.layout.add_widget(self.but4)
  60.         self.layout.add_widget(self.text)
  61.         self.text.font_size = 24
  62.         Clock.schedule_interval(self.text.update, 1)        
  63.         return self.layout
  64.    
  65.     def my_callback(self, dt):
  66.         self.text = "You haven't played Dota for:\n" + current_time(int(time.time() - START))
  67.    
  68. app = main()
  69. if __name__ in ('__main__', '__android__'):
  70.     app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement