Tkinter / Entry widget problem

2009-07-13 Thread Andras Szabo
Hello. I searched the archives but couldn't find a solution to a  
problem related to the Entry widget in Tkinter.


When creating a pop-up window in an app, which contains an Entry  
widget, I want this widget to contain some default string, to have all  
this default string selected (as if the user had manually selected  
everything), and to have the focus transferred to this widget.


(The idea is then that if the window pops up, the user won't have to  
click or press Tab any more before being able to type what is needed  
in the textbox, overwriting what is written there already.)


I thought this might be the way to go:

entrybox=Entry(toplevel_parent_window)
entrybox.insert(0,"Some default string")
entrybox.select_range(0,END)
entrybox.focus_set()
entrybox.pack()

But it doesn't seem to work - the focus is not transferred to the  
Entry widget, and the text does not appear to be selected (even though  
after this entrybox.selection_present() returns True).


What am I doing wrong?

andras
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter / Entry widget problem

2009-07-14 Thread Andras Szabo
So it's either that I use Python 2.5.1, or that I use it on a Mac.  
(John, your code still doesn't work the way it's supposed to here.) I  
guess I'll upgrade to 2.6.1 and see if it makes a difference. (The  
Tkinter/Tcl versions are the same for me.) Thanks for your help.


andras

On Jul 14, 2009, at 5:07 PM, John Posner wrote:




Andras Szabo wrote:



Hello. I searched the archives but couldn't find a solution to a
problem related to the Entry widget in Tkinter.

When creating a pop-up window in an app, which contains an Entry
widget, I want this widget to contain some default string, to have  
all

this default string selected (as if the user had manually selected
everything), and to have the focus transferred to this widget.

(The idea is then that if the window pops up, the user won't have to
click or press Tab any more before being able to type what is needed
in the textbox, overwriting what is written there already.)

I thought this might be the way to go:

entrybox=Entry(toplevel_parent_window)
entrybox.insert(0,"Some default string")
entrybox.select_range(0,END)
entrybox.focus_set()
entrybox.pack()

But it doesn't seem to work - the focus is not transferred to the
Entry widget, and the text does not appear to be selected (even  
though

after this entrybox.selection_present() returns True).

What am I doing wrong?



Nothing, I would think. Can you post a minimal runnable example?

Peter


This works for me, on Windows and Linux:

from Tkinter import *

rt = Tk()
rt.title("root window")
pop = Toplevel()
pop.title("second window")

entrybox=Entry(pop)
entrybox.insert(0,"Some default string")
entrybox.select_range(0,END)
entrybox.focus_set()
entrybox.pack()

rt.withdraw()
rt.mainloop()


On Win/XP SP3:

> python
Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit
 (Intel)] on   win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> Tkinter.TkVersion
8.5
>>> Tkinter.TclVersion
8.5

On Ubuntu Linux (Ubu-SL 2.6.27.14-generic):

$ python
Python 2.6.1 (r261:67515, Jan  9 2009, 19:06:23)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> Tkinter.TkVersion
8.4004
>>> Tkinter.TclVersion
8.4004


-John




--
http://mail.python.org/mailman/listinfo/python-list