How to get the mouse cursor position in TK?

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Mon Oct 7 20:41:10 CEST 2002


On Monday 07 Oct 2002 5:19 pm, Heiner Litz wrote:
> hi Thank u!
>
> event.x_root works but I have another Problem: I want to pop-up an whole
> new WINDOW, but the Tk() Objects dont know the gm place. So how can I place
> tk Objects, and NOT widgets inside a parent?

Not sure i'm following here but perhaps all you need is a Toplevel widget?


>
> 2. question:
> I have got the mentioned listbox and select one entry. Now If there is a
> right-mouse-button event I want to know what line was selected. Howtodo?
>

the listbox.curselection() method returns a tuple of indexes of the selected 
items (just one if single selection) the listbox.get(first=XXX) method will 
return the XXX't item in the list box so:-

index = int(listbox.curselection()[0])
item = listbox.get(first=index)



and from the command line:-

Python 2.2.1 (#3, May 29 2002, 20:32:44)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> lb=Tkinter.Listbox()
>>> lb.insert("end", "one")
>>> lb.insert("end", "two")
>>> lb.insert("end", "three")
>>> lb.pack()
>>> lb.curselection()
('1',)
>>> lb.get(first=int(lb.curselection()[0]))
'two'
>>>

should do the trick

I guess you need to get hold of some Tkinter documentation....:-

 http://www.python.org/topics/tkinter/

> thx again
>
> > Assuming you pass the event to the popup function
> > event.x_root and event.y_root should be what you want:

-- 
### Python Powered Signature
I started writting this email on 
Mon Oct  7 18:34:41 2002





More information about the Python-list mailing list