[/td][/tr]
[tr][td]程序代码:[/td][/tr]
[tr][td]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Thu Jul 19 15:47:52 2012
# design by ukonline2000 form
www.shumeipai.net
import wx
# begin wxGlade: extracode
import RPi.GPIO as GPIO
GPIO.setup(11,GPIO.OUT)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)
GPIO.setup(16,GPIO.OUT)
GPIO.setup(18,GPIO.OUT)
GPIO.setup(22,GPIO.OUT)
GPIO.setup(7,GPIO.OUT)
# end wxGlade
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.label_2 = wx.StaticText(self, -1, "GPIO0")
self.button_1 = wx.Button(self, -1, "ON")
self.button_5 = wx.Button(self, -1, "OFF")
self.label_3 = wx.StaticText(self, -1, "GPIO1")
self.button_2 = wx.Button(self, -1, "ON")
self.button_6 = wx.Button(self, -1, "OFF")
self.label_4 = wx.StaticText(self, -1, "GPIO2")
self.button_3 = wx.Button(self, -1, "ON")
self.button_7 = wx.Button(self, -1, "OFF")
self.label_5 = wx.StaticText(self, -1, "GPIO3")
self.button_4 = wx.Button(self, -1, "ON")
self.button_8 = wx.Button(self, -1, "OFF")
self.label_6 = wx.StaticText(self, -1, "GPIO4")
self.button_9 = wx.Button(self, -1, "ON")
self.button_10 = wx.Button(self, -1, "OFF")
self.label_7 = wx.StaticText(self, -1, "GPIO5")
self.button_11 = wx.Button(self, -1, "ON")
self.button_12 = wx.Button(self, -1, "OFF")
self.label_8 = wx.StaticText(self, -1, "GPIO6")
self.button_13 = wx.Button(self, -1, "ON")
self.button_14 = wx.Button(self, -1, "OFF")
self.label_9 = wx.StaticText(self, -1, "GPIO7")
self.button_15 = wx.Button(self, -1, "ON")
self.button_16 = wx.Button(self, -1, "OFF")
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_BUTTON, self.on0, self.button_1)
self.Bind(wx.EVT_BUTTON, self.off0, self.button_5)
self.Bind(wx.EVT_BUTTON, self.on1, self.button_2)
self.Bind(wx.EVT_BUTTON, self.off1, self.button_6)
self.Bind(wx.EVT_BUTTON, self.on2, self.button_3)
self.Bind(wx.EVT_BUTTON, self.off2, self.button_7)
self.Bind(wx.EVT_BUTTON, self.on3, self.button_4)
self.Bind(wx.EVT_BUTTON, self.off3, self.button_8)
self.Bind(wx.EVT_BUTTON, self.on4, self.button_9)
self.Bind(wx.EVT_BUTTON, self.off4, self.button_10)
self.Bind(wx.EVT_BUTTON, self.on5, self.button_11)
self.Bind(wx.EVT_BUTTON, self.off5, self.button_12)
self.Bind(wx.EVT_BUTTON, self.on6, self.button_13)
self.Bind(wx.EVT_BUTTON, self.off6, self.button_14)
self.Bind(wx.EVT_BUTTON, self.on7, self.button_15)
self.Bind(wx.EVT_BUTTON, self.off7, self.button_16)
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("Raspi GPIO Demo")
self.SetSize((246, 330))
self.label_2.SetMinSize((80, 40))
self.label_2.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
self.button_1.SetMinSize((80, 40))
self.button_5.SetMinSize((80, 40))
self.label_3.SetMinSize((80, 40))
self.label_3.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
self.button_2.SetMinSize((80, 40))
self.button_6.SetMinSize((80, 40))
self.label_4.SetMinSize((80, 40))
self.label_4.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
self.button_3.SetMinSize((80, 40))
self.button_7.SetMinSize((80, 40))
self.label_5.SetMinSize((80, 40))
self.label_5.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
self.button_4.SetMinSize((80, 40))
self.button_8.SetMinSize((80, 40))
self.label_6.SetMinSize((80, 40))
self.label_6.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
self.button_9.SetMinSize((80, 40))
self.button_10.SetMinSize((80, 40))
self.label_7.SetMinSize((80, 40))
self.label_7.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
self.button_11.SetMinSize((80, 40))
self.button_12.SetMinSize((80, 40))
self.label_8.SetMinSize((80, 40))
self.label_8.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
self.button_13.SetMinSize((80, 40))
self.button_14.SetMinSize((80, 40))
self.label_9.SetMinSize((80, 40))
self.label_9.SetFont(wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
self.button_15.SetMinSize((80, 40))
self.button_16.SetMinSize((80, 40))
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
grid_sizer_1 = wx.GridSizer(8, 3, 0, 0)
grid_sizer_1.Add(self.label_2, 0, 0, 0)
grid_sizer_1.Add(self.button_1, 0, 0, 0)
grid_sizer_1.Add(self.button_5, 0, 0, 0)
grid_sizer_1.Add(self.label_3, 0, 0, 0)
grid_sizer_1.Add(self.button_2, 0, 0, 0)
grid_sizer_1.Add(self.button_6, 0, 0, 0)
grid_sizer_1.Add(self.label_4, 0, 0, 0)
grid_sizer_1.Add(self.button_3, 0, 0, 0)
grid_sizer_1.Add(self.button_7, 0, 0, 0)
grid_sizer_1.Add(self.label_5, 0, 0, 0)
grid_sizer_1.Add(self.button_4, 0, 0, 0)
grid_sizer_1.Add(self.button_8, 0, 0, 0)
grid_sizer_1.Add(self.label_6, 0, 0, 0)
grid_sizer_1.Add(self.button_9, 0, 0, 0)
grid_sizer_1.Add(self.button_10, 0, 0, 0)
grid_sizer_1.Add(self.label_7, 0, 0, 0)
grid_sizer_1.Add(self.button_11, 0, 0, 0)
grid_sizer_1.Add(self.button_12, 0, 0, 0)
grid_sizer_1.Add(self.label_8, 0, 0, 0)
grid_sizer_1.Add(self.button_13, 0, 0, 0)
grid_sizer_1.Add(self.button_14, 0, 0, 0)
grid_sizer_1.Add(self.label_9, 0, 0, 0)
grid_sizer_1.Add(self.button_15, 0, 0, 0)
grid_sizer_1.Add(self.button_16, 0, 0, 0)
sizer_1.Add(grid_sizer_1, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
self.Layout()
# end wxGlade
def on0(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 0 is ON!"
GPIO.output(11,True)
event.Skip()
def off0(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 0 is OFF!"
GPIO.output(11,False)
event.Skip()
def on1(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 1 is ON!"
GPIO.output(12,True)
event.Skip()
def off1(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 1 is OFF!"
GPIO.output(12,False)
event.Skip()
def on2(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 2 is ON!"
GPIO.output(13,True)
event.Skip()
def off2(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 2 is OFF!"
GPIO.output(13,False)
event.Skip()
def on3(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 3 is ON!"
GPIO.output(15,True)
event.Skip()
def off3(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 3 is OFF!"
GPIO.output(15,False)
event.Skip()
def on4(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 4 is ON!"
GPIO.output(16,True)
event.Skip()
def off4(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 4 is OFF!"
GPIO.output(16,False)
event.Skip()
def on5(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 5 is ON!"
GPIO.output(18,True)
event.Skip()
def off5(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 5 is OFF!"
GPIO.output(18,False)
event.Skip()
def on6(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 6 is ON!"
GPIO.output(22,True)
event.Skip()
def off6(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 6 is OFF!"
GPIO.output(22,False)
event.Skip()
def on7(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 7 is ON!"
GPIO.output(7,True)
event.Skip()
def off7(self, event): # wxGlade: MyFrame.<event_handler>
print "GPIO 7 is OFF!"
GPIO.output(7,False)
event.Skip()
# end of class MyFrame
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~