Advertisement
Guest User

Python

a guest
Oct 16th, 2016
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import Tkinter as tk
  2. import RPi.GPIO as GPIO
  3.  
  4. # Warnungen ausschalten
  5. GPIO.setwarnings(False)
  6. #Boardmodus
  7. GPIO.setmode(GPIO.BCM)
  8. #setzen des GPIO 23 auf HIGH
  9. GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  10.  
  11.  
  12. nummer = 0
  13.  
  14. def update_timeText():
  15. if (state):
  16. global timer
  17. timer[2] += 1
  18.  
  19. if (timer[2] >= 100):
  20. timer[2] = 0
  21. timer[1] += 1
  22.  
  23. if (timer[1] >= 60):
  24. timer[0] += 1
  25. timer[1] = 0
  26.  
  27. timeString = pattern.format(timer[0], timer[1], timer[2])
  28.  
  29. timeText.configure(text=timeString)
  30.  
  31. root.after(10, update_timeText)
  32.  
  33.  
  34. def start():
  35. global state
  36. GPIO.wait_for_edge(22, GPIO.FALLING)
  37. state = True
  38.  
  39. def stop():
  40. global state
  41. state = False
  42.  
  43. def exist():
  44. root.destroy()
  45.  
  46. def zeiten():
  47. global timer
  48. global nummer
  49. print "Dauer: ", timer
  50. file = open("log.txt", "a")
  51. file.write("Teil" + " #" + repr(nummer) + " " + repr(timer) + '\n')
  52. nummer += 1
  53. timer = [0, 0, 0]
  54. timeText.configure(text='00:00:00')
  55.  
  56.  
  57.  
  58. state = False
  59.  
  60.  
  61. root = tk.Tk()
  62. self = root
  63.  
  64. self.overrideredirect(1)
  65. w, h = self.winfo_screenwidth(), self.winfo_screenheight()
  66. self.geometry("%dx%d+0+0" % (w, h))
  67.  
  68. root.wm_title('Stoppuhr')
  69.  
  70. timer = [0, 0, 0]
  71.  
  72. pattern = '{0:02d}:{1:02d}:{2:02d}'
  73.  
  74.  
  75. timeText = tk.Label(root, text="00:00:00", font=("Helvetica", 150))
  76. timeText.pack()
  77.  
  78. startButton = tk.Button(root, text='Start', command=start)
  79. startButton.pack()
  80.  
  81. pauseButton = tk.Button(root, text='Stop', command=stop and zeiten)
  82. pauseButton.pack()
  83.  
  84. quitButton = tk.Button(root, text='Quit', command=exist)
  85. quitButton.pack()
  86.  
  87. update_timeText()
  88. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement