#获取搜索框中的字符串 e = tkinter.Entry() searcStr = e.get() #是否有选中字符 is_checked = e.select_present() checked_str = "" if is_checked: #checked_str = e.select_get() #获取选中的文本 start_index = e.index(tkinter.ANCHOR) #开始选择时的index end_index = e.index(tkinter.INSERT) #结束选择时的index if start_index < end_index: #从左向右选择 checked_str = searcStr[start_index : end_index] elif start_index > end_index: #从右向左选择 checked_str = searcStr[end_index : start_index] else: checked_str = ""