开发者

Tkinter Python Entry state attribute

I am trying to check if the users cursor is in a text box by checking the Entries state value. However, I get "AttributeError: Entry instance has no attribute 'state'". How do I check if the users cursor is in a textbox?

import os

from Tkinter import *

textboxes = []

def read_textboxes():
    for e in textboxes:
        print e.state

root = Tk()
for i in range(5):
    textboxes.append(Entry(root))
    textboxes[i].insert(0,"I am textbox #"+str(i))
    textboxes[i].grid(row = i,column = 0)
button = Button(r开发者_开发问答oot,text = "Read Textboxes",command = read_textboxes)
button.grid(row = len(textboxes),columnspan = 99,pady = 10)
mainloop()


You can call focus_get() on the root to get the widget that currently has the focus.

def read_textboxes():
    in_focus = root.focus_get()
    for e in textboxes:
        print e == in_focus
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜