Raspberry pi GPIO pins to control Tkinter GUI stopwatch

眉间皱痕 提交于 2019-12-02 11:10:17

Makezine propose an extensive tutorial of GPIO use.

You could poll buttons values in your _update method.

if self._running and (GPIO.input(23) ==1):
    self.Stop()

This will not work when your clock is not running, so you might adapt your logic to have your _update after-loop to be always running (or create another after-loop dedicated to Pi buttons polling).

Also, GPIO provide a waitloop in another thread. Here is an adaptation of Makezine's example to link back to tkinter (not tested).

def relayToTkinter(channel):
    sw.event_generate('<<Start>>', when='tail')

GPIO.add_event_detect(23, GPIO.RISING, callback=relayToTkinter, bouncetime=300)
sw.bind("<<Start>>", lambda event:sw.Start())

event_generate("<<VirtualEvent>>", when='tail') is a safe way to have another thread interact with main UI thread.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!