I want to show the spacy output in my second textbox from tkinter, however I just manage to read the text file that i want to tokenize, I need to read the spacy output with the text file already tokenized, this is how it's my code to show the pre-tokenize text, how can i get the spacy output in the textbox?
nlp = es_core_news_sm.load()
doc = nlp(open('rainbow.txt').read())
for token in doc:
print(token.text,",")
def tokenize():
stuff2 = doc=nlp(open('rainbow.txt').read())
my_text2.insert(END, stuff2)
text_file.close()
open_button2 = Button(root, text="Compilar", command=tokenize)
open_button2.place(x=5,y=5)
root.mainloop()
I need to get the
print(token.text,",")
output for the button 2
I need to get the print token output for the textbox 2
CodePudding user response:
This standalone code should work for what you are trying to do. You might have to change a few things back because I dont have spacy not do I know how to use it, and I dont have the same files that you have.
nlp = es_core_news_sm.load()
doc = nlp(open('rainbow.txt').read())
for token in doc:
print(token.text,",")
def tokenize():
stuff2 = token.text, ","
my_text2.insert(END, stuff2)
open_button2 = Button(root, text="Compilar", command=tokenize)
open_button2.place(x=5,y=5)
root.mainloop()
You can run this code and see why/how it works and work off of that.
CodePudding user response:
ok I managed to get the token.text output in my textbox, however it's just giving me the last word of the token.text, how can i get all the words from the token.text in the tkinter textbox? with append?
nlp = es_core_news_sm.load()
doc = nlp(open('rainbow.txt').read())
for token in doc:
print(token.text,",")
def tokenize():
stuff2 = token.text, ","
my_text2.insert(END, stuff2)
open_button2 = Button(root, text="Compilar", command=tokenize)
open_button2.place(x=5,y=5)
root.mainloop()
This is what i get in the textbox, however I need to get all the words as i get it on python lines: