#---------------------------------------------------------------------- # A very simple wxPython example. Just a wx.Frame, wx.Panel, # wx.StaticText, wx.Button, and a wx.BoxSizer, but it shows the basic # structure of any wxPython application. #---------------------------------------------------------------------- import wx import random next = 1 sets = ['A a', 'B b', 'C c', 'D d', 'E e', 'F f', 'G g', 'H h', 'I i', 'J j', 'K k', 'L l', 'M m', 'N n', 'O o', 'P p', 'Q q', 'R r', 'S s', 'T t', 'U u', 'V v', 'W w', 'X x', 'Y y', 'Z z'] class MyFrame(wx.Frame): """ This is MyFrame. It just shows a few controls on a wxPanel, and has a simple menu. """ def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(600, 500)) # Create the menubar menuBar = wx.MenuBar() # and a menu menu = wx.Menu() # add an item to the menu, using \tKeyName automatically # creates an accelerator, the third param is some help text # that will show up in the statusbar menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample") # bind the menu event to an event handler self.Bind(wx.EVT_MENU, self.OnTimeToQuit, id=wx.ID_EXIT) self.Bind(wx.EVT_CHAR_HOOK, self.onKeyEvent) # and put the menu on the menubar menuBar.Append(menu, "&File") self.SetMenuBar(menuBar) self.CreateStatusBar() # Now create the Panel to put the other controls on. panel = wx.Panel(self) # and a few controls global sets r = random.randint(0,len(sets)) text = wx.StaticText(panel, -1, sets[r:r+1][0]) text.SetFont(wx.Font(280, wx.SWISS, wx.NORMAL, wx.BOLD)) text.SetSize(text.GetBestSize()) nbtn = wx.Button(panel, -1, "Close") btn = wx.Button(panel, -1, "Next") # bind the button events to handlers self.Bind(wx.EVT_BUTTON, self.OnTimeToQuit, nbtn) self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn) # Use a sizer to layout the controls, stacked vertically and with # a 10 pixel border around each sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(text, 0, wx.ALL, 10) sizer.Add(btn, 0, wx.ALL, 10) sizer.Add(nbtn, 0, wx.ALL, 10) panel.SetSizer(sizer) panel.Layout() def onKeyEvent(self, evt): print "test" print evt.KeyCode() def OnTimeToClose(self, evt): """Event handler for the button click.""" self.Close() def OnTimeToQuit(self, evt): global next next = 0 self.Close() class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, "Simple wxPython App") self.SetTopWindow(frame) frame.Show(True) return True while next: app = MyApp(redirect=True) app.MainLoop()