I am working on a fairly simple wxpython GUI and want the activation key to close the window. Right now I have a close button that executes sys.exit (0), but I would like the escape key to do this.
Does anyone know how to do this?
import win32clipboard import wx from time import sleep import sys class MainFrame(wx.Frame): def __init__(self,title): wx.Frame.__init__(self, None, title="-RRESI Rounder-", pos=(0,0), size=(210,160)) panel=Panel(self) icon = wx.Icon('ruler_ico.ico', wx.BITMAP_TYPE_ICO) self.SetIcon(icon) class Panel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent) x1=10; x2=110 y1=40; dy=25; ddy=-3 boxlength=80 self.button =wx.Button(self, label="GO", pos=(100,y1+dy*3)) self.Bind(wx.EVT_BUTTON, self.OnClick,self.button) self.button.SetDefault() self.button2 =wx.Button(self, label="Close", pos=(100,y1+dy*4)) self.Bind(wx.EVT_BUTTON, self.OnClose, self.button2) self.button.SetDefault() self.Bind(wx.EVT_KEY_UP, self.OnKeyUP) self.label1 = wx.StaticText(self, label="Input Number:", pos=(x1,y1+dy*1)) self.Input = wx.TextCtrl(self, value="1.001", pos=(x2,ddy+y1+dy*1), size=(boxlength,-1)) self.label0 = wx.StaticText(self, label="Round to closest: 1/", pos=(x1,y1+dy*0)) self.Denominator = wx.TextCtrl(self, value="64", pos=(x2,ddy+y1+dy*0), size=(boxlength,-1)) self.label2 = wx.StaticText(self, label="Output Number:", pos=(x1,y1+dy*2)) self.display = wx.TextCtrl(self, value="1.0", pos=(x2,ddy+y1+dy*2), size=(boxlength,-1)) self.display.SetBackgroundColour(wx.Colour(232, 232, 232)) self.label3 = wx.StaticText(self, label=" ", pos=(x2+7,y1+dy*2+20))