Tkinter and setting focus 
Author Message
 Tkinter and setting focus

I have created a class wich expands the standard entry widget.
In that class i did a override of the return key to do some validation
of my entry

self.entry.bind(<return>,self.validate)

The validation routine works fine, but now comes my problem

I want at the end of the validation, if validation is ok set the focus
to the next entry widget in the form.
I searched documentation but didn't find anything on this.
The problem is since my class is a general class, i don't know in the
class wich widget is the next to put the
focus on.
Here is some code to show what i'm doing:
class numentry:
 def
__init__(self,parent,rw,clmn,wdt,relf=SUNKEN,mask='$',min=0,max=999999999):

  self.w = wdt
  self.m = mask
  self.min = min
  self.max = max
  self.field = Entry(parent,relief=SUNKEN,width=wdt)
  self.field.grid(row=rw,column=clmn)
  self.field.bind("<Return>",self.validate)
  self.returnval=''
  self.ind = 0
  self.pointindex = 0

 def validate(self,event):
    # do some validation
===> here i want to set the focus to the next widget

#main
frame = Frame(root,width=100,height=100)
# frame.bind("<Up>",callback)
frame.pack()
f=numentry(frame,1,1,10,SUNKEN,'0000.00',5)
f2=numentry(frame,2,1,10,SUNKEN,'0000.00')
root.mainloop()

I'm realy sticked on that ?????
Anyone has a idea how to do that

Rony Steelandt
--
======================================================
Bureau de Conseil et de Dveloppement Informatique
2, Rue Henri Avril
22480 Saint - Nicolas du Pelem

Tl : +33.2.96.29.79.08
Fax : +33.2.96.29.79.09


======================================================



Sat, 07 Dec 2002 03:00:00 GMT  
 Tkinter and setting focus
Hi Rony,

You could just generate your own tab event (I presume that's the behaviour
you want)

So:

def validate(self,event):
        # do some validation
        self.field.event_generate('<Tab>')

Richard


Quote:

> I have created a class wich expands the standard entry widget.
> In that class i did a override of the return key to do some validation
> of my entry

> self.entry.bind(<return>,self.validate)

> The validation routine works fine, but now comes my problem

> I want at the end of the validation, if validation is ok set the focus
> to the next entry widget in the form.
> I searched documentation but didn't find anything on this.
> The problem is since my class is a general class, i don't know in the
> class wich widget is the next to put the
> focus on.
> Here is some code to show what i'm doing:
> class numentry:
>  def

__init__(self,parent,rw,clmn,wdt,relf=SUNKEN,mask='$',min=0,max=999999999):

- Show quoted text -

Quote:

>   self.w = wdt
>   self.m = mask
>   self.min = min
>   self.max = max
>   self.field = Entry(parent,relief=SUNKEN,width=wdt)
>   self.field.grid(row=rw,column=clmn)
>   self.field.bind("<Return>",self.validate)
>   self.returnval=''
>   self.ind = 0
>   self.pointindex = 0

>  def validate(self,event):
>     # do some validation
> ===> here i want to set the focus to the next widget

> #main
> frame = Frame(root,width=100,height=100)
> # frame.bind("<Up>",callback)
> frame.pack()
> f=numentry(frame,1,1,10,SUNKEN,'0000.00',5)
> f2=numentry(frame,2,1,10,SUNKEN,'0000.00')
> root.mainloop()

> I'm realy sticked on that ?????
> Anyone has a idea how to do that

> Rony Steelandt
> --
> ======================================================
> Bureau de Conseil et de Dveloppement Informatique
> 2, Rue Henri Avril
> 22480 Saint - Nicolas du Pelem

> Tl : +33.2.96.29.79.08
> Fax : +33.2.96.29.79.09


> ======================================================



Sat, 07 Dec 2002 03:00:00 GMT  
 Tkinter and setting focus
Thank you Richard, exactly what i needed. I didn't know you could that

Rony

richard_chamberlain a crit :

Quote:
> Hi Rony,

> You could just generate your own tab event (I presume that's the behaviour
> you want)

> So:

> def validate(self,event):
>         # do some validation
>         self.field.event_generate('<Tab>')

> Richard



> > I have created a class wich expands the standard entry widget.
> > In that class i did a override of the return key to do some validation
> > of my entry

> > self.entry.bind(<return>,self.validate)

> > The validation routine works fine, but now comes my problem

> > I want at the end of the validation, if validation is ok set the focus
> > to the next entry widget in the form.
> > I searched documentation but didn't find anything on this.
> > The problem is since my class is a general class, i don't know in the
> > class wich widget is the next to put the
> > focus on.
> > Here is some code to show what i'm doing:
> > class numentry:
> >  def

> __init__(self,parent,rw,clmn,wdt,relf=SUNKEN,mask='$',min=0,max=999999999):

> >   self.w = wdt
> >   self.m = mask
> >   self.min = min
> >   self.max = max
> >   self.field = Entry(parent,relief=SUNKEN,width=wdt)
> >   self.field.grid(row=rw,column=clmn)
> >   self.field.bind("<Return>",self.validate)
> >   self.returnval=''
> >   self.ind = 0
> >   self.pointindex = 0

> >  def validate(self,event):
> >     # do some validation
> > ===> here i want to set the focus to the next widget

> > #main
> > frame = Frame(root,width=100,height=100)
> > # frame.bind("<Up>",callback)
> > frame.pack()
> > f=numentry(frame,1,1,10,SUNKEN,'0000.00',5)
> > f2=numentry(frame,2,1,10,SUNKEN,'0000.00')
> > root.mainloop()

> > I'm realy sticked on that ?????
> > Anyone has a idea how to do that

> > Rony Steelandt
> > --
> > ======================================================
> > Bureau de Conseil et de Dveloppement Informatique
> > 2, Rue Henri Avril
> > 22480 Saint - Nicolas du Pelem

> > Tl : +33.2.96.29.79.08
> > Fax : +33.2.96.29.79.09


> > ======================================================

--
======================================================
Bureau de Conseil et de Dveloppement Informatique
2, Rue Henri Avril
22480 Saint - Nicolas du Pelem

Tl : +33.2.96.29.79.08
Fax : +33.2.96.29.79.09


======================================================



Sun, 08 Dec 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. setting focus in Tkinter

2. TKinter and focus events

3. Tkinter/Pmw and focus events

4. Python (1.5) / Tkinter / Pmw (0.6.1): problem with focus after modal dialog disappears

5. Tkinter focus commands

6. focus problem with full-screen in Tkinter

7. Tkinter focus problem

8. tkinter and focus...

9. Tkinter list boxes, selection emphasis, and the keyboard focus

10. Tkinter window on top without keyboard focus?

11. Tkinter focus problem

12. Need help with moving focus using Tkinter

 

 
Powered by phpBB® Forum Software