[Tkinter-discuss] about getting cursor's position
V H
haofast2006 at hotmail.com
Fri Oct 20 15:31:33 CEST 2006
Hi,
I have created a Text on a Frame. A button "Mark" can change the color of
the second line in the Text. When the cursor moves to the second line, some
explaination is needed. I use Toplevel for that.
Now I prefer the Toplevel window is generated besides the cursor. How can I
get the position of the cursor? It should not be the relative position
because the fuction geometry() uses the absolute one.
Thanks in advance.
best regards,
Weining
Following is the code:
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
self.master = master
self.text = Text(frame)
self.text.insert(END,"line1\n")
self.text.insert(END,"line2\n")
self.text.insert(END,"line3")
self.text.pack()
b = Button(frame, text = 'Mark', command= self.markit).pack()
frame.pack()
def markit(self):
line2= self.text.get(2.0, 3.0)
h1= 'h11'
self.text.tag_config(h1,foreground= 'blue', wrap= WORD, font = 'system
12 bold')
self.text.tag_bind(h1, "<Enter>", self.show_warning)
self.text.tag_bind(h1, "<Leave>", self.hide_warning)
self.text.delete(2.0, 3.0)
self.text.insert(2.0, line2, h1)
def show_warning(self, event):
self.win = Toplevel(self.master)
l = Label(self.win, text = "Some error.").pack()
self.win.geometry('+400+200')
def hide_warning(self, event):
self.win.destroy()
root = Tk()
app = App(root)
root.mainloop()
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
More information about the Tkinter-discuss
mailing list