searching in strings from tk-inter text fails

Why does the search fail when taking a string from a tk-inter text box? The search works fine if I define the keyword as a string.

Minimal example:

import tkinter as tk
root = tk.Tk()
string="banana\napplepie\napple\n"

def searchcall():
 
    textboxcontent=textExample.get("1.0","end")
    keyword=filterbox.get("1.0","end")
    keyword="apple" # search works as expected

    print("keyword",keyword)
    print("is keyword in textbox",keyword in textboxcontent)
    for elem in textboxcontent.split():
        print("seaching for",keyword,"in",elem,keyword in elem)
 
        

textExample=tk.Text(root, height=10)
textExample.insert(1.0,string)
textExample.pack()
filterbox=tk.Text(root, height=1)
filterbox.insert(1.0,"apple")
filterbox.pack()
btnRead=tk.Button(root, height=1, width=11, text="search", 
                    command=searchcall)

btnRead.pack()
root.mainloop()


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations