0

I am trying to get input through tkinter text widget. I saw posts about tkinter text widget input. But those didn't work for me. I saw post on and tried that but I couldn't understand what is wrong with it. Here is my code.

`corpusinput = Text(rooter, width=50, height=10)
 corpustext = corpusinput.get("1.0", "end-1c")
 corpusinput.grid(row=2, column=1, sticky='nsew')
 print(corpustext)`

This prints a blank space/line without any character.

Abdullah Al Mubin
  • 123
  • 1
  • 2
  • 10

1 Answers1

2

You're calling the .get() method on the widget just after you've created it. At this point the widget is blank, so .get() will return''.

You need to setup a way of calling .get() whilst the program is running, eg. a button

corpusinput = Text(rooter, width=50, height=10)
corpusinput.grid()

get_input = Button(rooter, text='Print', command= lambda x=corpusinput.get() : print(x))
get_input.grid()
strava
  • 765
  • 6
  • 14