Use tab key for change textctrl

Andrea amarin at mr-service.it
Tue Apr 3 02:04:51 PDT 2007


Hi all,

I am a new user of wxPython and I write a little gui for take some
information with textctrl and save it into a file.

I have a strange problem, I cannot change focus between the textctrl
with the tab key, I must use the mouse for point the focus into the text
ctrl.

I make a mistake or by default this function is able?

Thanks Andrea
My code:

class MainWindow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,
wx.Size(500, 400))
	
# Create MenuBar
        menubar = wx.MenuBar()
# Create item Menu of MenuBar        
        file = wx.Menu()
        edit = wx.Menu()
        help = wx.Menu()
#File menu items   
        file.Append(101, '&Open\tCtrl+O', 'Open document...')
        file.Append(102, '&Save\tCtrl+S', 'Save document...')
        file.AppendSeparator()
        quit = wx.MenuItem(file, 105, '&Quit\tCtrl+Q', 'Quit Kory
Application')
        file.AppendItem(quit)
#Edit menu ites       
        edit.Append(201, 'Wiev List', 'Wiev list mode')#,
kind=wx.ITEM_CHECK)
        edit.Append(202, 'Wiev Tree', 'Wiev tree mode')#,
kind=wx.ITEM_CHECK)
# Sub menu of edit items      
        submenu = wx.Menu()
        submenu.Append(301, 'Red', kind=wx.ITEM_RADIO)
        submenu.Append(302, 'Blue', kind=wx.ITEM_RADIO)
        submenu.Append(303, 'Yellow', kind=wx.ITEM_RADIO)
        edit.AppendMenu(203, 'Set Colors', submenu)
#Help menu items	
	help.Append(401, '&About\tCtrl+A', 'About Kory Application')
#Attach menu to the menubar        
        menubar.Append(file, '&File')
        menubar.Append(edit, '&Edit')
        menubar.Append(help, '&Help')
        self.SetMenuBar(menubar)
        self.Centre()
#Attach the menu-event to the method       
        self.Bind(wx.EVT_MENU, self.OnSave, id=102)
        self.Bind(wx.EVT_MENU, self.OnAbout, id=401)
        self.Bind(wx.EVT_MENU, self.OnQuit, id=105)
#Create and customize StatusBar	
	self.CreateStatusBar()
	self.SetStatusText('Kory Application...')
#Add panel between menubar and statusbar	
	self.panel = wx.Panel(self)
#Create control on the panel
	nameLbl = wx.StaticText(self, -1, 'Ragione Sociale:', pos = (0, 15))
	localLbl = wx.StaticText(self, -1, 'Totale costo locali:', pos = (0,
45))
	scontolocalLbl = wx.StaticText(self, -1, 'Sconto locali:', pos =(0,
75))
	self.name = wx.TextCtrl(self, -1, '', pos = (200,15), size = (200, -1))
	self.local = wx.TextCtrl(self, -1, '', pos = (200, 45))
	self.scontolocal = wx.TextCtrl(self, -1, '', pos = (200, 75))
#Create control buttom
	b = wx.Button(self, -1, 'Save', pos = (0, 300))
	self.Bind(wx.EVT_BUTTON, self.OnSave, b)

#Create event def section
    
    def OnSave(self, event):
#Get value from user
    	rag_soc = self.name.GetValue()
    	tot_local = self.local.GetValue()
    	scontolocal_mr = self.scontolocal.GetValue()
#Create a dictionary for save data into a file
    	self.data = {}
	self.data['Ragione_Sociale'] = rag_soc
	self.data['Costo_Locali'] = tot_local
	self.data['Sconto_mr_locali'] = scontolocal_mr
    	self.dirname = ''
    	dlg = wx.FileDialog(self, "Chose a file", self.dirname, '', '*.*',
wx.SAVE)
    	if dlg.ShowModal() == wx.ID_OK:	
    		self.filename = dlg.GetFilename()
    		self.dirname = dlg.GetDirectory()
    		f = open(os.path.join(self.dirname, self.filename), 'w')
    		pickle.dump(self.data, f)
    		f.close()
    	dlg.Destroy

    def OnQuit(self, event):
        self.Close()

    def OnAbout(self, event):
    	msg = "This is the Kory application for analisys of calls cost.\n"
+ \
              "Author: Andrea Marin @ 02 Apr 2007\n" + \
              "Please report any Bug/Requests of improvements\n" + \
              "to me at the following adresses:\n\n" + \
              "amarin at mr-service.it\n" + "baba-andrea at jabber.org\n\n" +
\
              "GUI with wxPython " + wx.VERSION_STRING + " !!!"
              
        dlg = wx.MessageDialog(self, msg, "About panel Kory
application", 
        			wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
	
class MyApp(wx.App):
    def OnInit(self):
    	frame = MainWindow(None, -1, 'Welcome to Kory Application')
        frame.Show(True)
        return True

app = MyApp()
app.MainLoop()





More information about the wxpython-users mailing list