Bonjour à tous,
Maan, je ne sais pas si tu as résolu ton problème ,
mais voici ci-après une solution en installant un Panel car j'ai cru
comprendre que la navigation par TAB est possible qu'avec les widget
wx.dialog et wx.Panel.
(voir http://wxpython.org/docs/api/wx.NavigationKeyEvent-class.html)
J'ai modifié ton exemple pour ajouter ce panel et changer un petit peu
l'emplacement des objets dans le gridBackSizer.
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
try:
import wx
except ImportError:
raise ImportError,"The wxPython module is required to run this program"
class simpleapp_wx(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,id,title)
self.parent = parent
self.initialize()
def initialize(self):
panel = wx.Panel(self, -1,style=wx.TAB_TRAVERSAL)
sizer = wx.GridBagSizer(2,5)
self.entry = wx.TextCtrl(panel,-1,value=u"Enter text here.")
sizer.Add(self.entry,(0,0),(1,2),wx.EXPAND)
self.Bind(wx.EVT_TEXT_ENTER, self.OnPressEnter, self.entry)
button = wx.Button(panel,-1,label="Click me !")
sizer.Add(button, (0,3))
self.Bind(wx.EVT_BUTTON, self.OnButtonClick, button)
buttonn = wx.Button(panel,-1,label="bonjour!")
sizer.Add(buttonn, (0,4))
self.label = wx.StaticText(self,-1,label=u'Hello !')
self.label.SetBackgroundColour(wx.BLUE)
self.label.SetForegroundColour(wx.WHITE)
sizer.Add( self.label, (1,0),(1,2), wx.EXPAND )
sizer.AddGrowableCol(0)
panel.SetSizerAndFit(sizer)
panel.SetSizeHints(-1,self.GetSize().y,-1,self.GetSize().y );
self.entry.SetFocus()
self.entry.SetSelection(-1,-1)
self.Show(True)
def OnButtonClick(self,event):
self.label.SetLabel( self.entry.GetValue() + " (You clicked the
button)" )
self.entry.SetFocus()
self.entry.SetSelection(-1,-1)
def OnPressEnter(self,event):
self.label.SetLabel( self.entry.GetValue() + " (You pressed
ENTER)" )
self.entry.SetFocus()
self.entry.SetSelection(-1,-1)
if __name__ == "__main__":
app = wx.App()
frame = simpleapp_wx(None,-1,'my application')
app.MainLoop()
Amitiés.
Paul.
Le 08/05/2012 15:16, Maan ALOUN a écrit :
>
> bonjour,
>
> j'ai récupéré cet exemple en python, mais comment je peux parcourir les
> controls dans l'interface d'exécution avec la touche tab?
>
> #!/usr/bin/python
> # -*- coding: iso-8859-1 -*-
>
> try:
> import wx
> except ImportError:
> raise ImportError,"The wxPython module is required to run this program"
>
> class simpleapp_wx(wx.Frame):
> def __init__(self,parent,id,title):
> wx.Frame.__init__(self,parent,id,title)
> self.parent = parent
> self.initialize()
>
> def initialize(self):
> sizer = wx.GridBagSizer()
> TabFocus
> self.entry = wx.TextCtrl(self,-1,value=u"Enter text here.")
> sizer.Add(self.entry,(0,0),(1,1),wx.EXPAND)
> self.Bind(wx.EVT_TEXT_ENTER, self.OnPressEnter, self.entry)
>
> button = wx.Button(self,-1,label="Click me !")
> sizer.Add(button, (0,1))
> self.Bind(wx.EVT_BUTTON, self.OnButtonClick, button)
> buttonn = wx.Button(self,-1,label="bonjour!")
> sizer.Add(buttonn, (0,4))
>
>
>
> self.label = wx.StaticText(self,-1,label=u'Hello !')
> self.label.SetBackgroundColour(wx.BLUE)
> self.label.SetForegroundColour(wx.WHITE)
> sizer.Add( self.label, (1,0),(1,2), wx.EXPAND )
>
> sizer.AddGrowableCol(0)
> self.SetSizerAndFit(sizer)
> self.SetSizeHints(-1,self.GetSize().y,-1,self.GetSize().y );
> self.entry.SetFocus()
> self.entry.SetSelection(-1,-1)
> self.Show(True)
>
> def OnButtonClick(self,event):
> self.label.SetLabel( self.entry.GetValue() + " (You clicked the
> button)" )
> self.entry.SetFocus()
> self.entry.SetSelection(-1,-1)
>
> def OnPressEnter(self,event):
> self.label.SetLabel( self.entry.GetValue() + " (You pressed
> ENTER)" )
> self.entry.SetFocus()
> self.entry.SetSelection(-1,-1)
>
> if __name__ == "__main__":
> app = wx.App()
> frame = simpleapp_wx(None,-1,'my application')
> app.MainLoop()
>
>
>
> Maan
>
>
> Progliste :
> Pour se désinscrire de la liste :
> mailto:[email protected]?subject=unsubscribe
>
> Pour voir les archives de la liste :
> http://www.mail-archive.com/[email protected]/
>
> Pour accéder aux fichiers de la liste
> http://outils.archive-host.com/partage.php?id=2Qar9Hy6ftzr
> Pour y ajouter des fichiers demandez-moi le ou sur la liste ou en privé, je
> vous répondrez en privé.
>
Progliste :
Pour se désinscrire de la liste :
mailto:[email protected]?subject=unsubscribe
Pour voir les archives de la liste :
http://www.mail-archive.com/[email protected]/
Pour accéder aux fichiers de la liste
http://outils.archive-host.com/partage.php?id=2Qar9Hy6ftzr
Pour y ajouter des fichiers demandez-moi le ou sur la liste ou en privé, je
vous répondrez en privé.