To get Tkinter input from the text box, you must add a few more attributes to the normal .get() function. If we have a text box myText_Box, then this is the method for retrieving its input.
def retrieve_input():
input = self.myText_Box.get("1.0",END)
The first part, "1.0" means that the input should be read from line one, character zero (ie: the very first character). END is an imported constant which is set to the string "end". The END part means to read until the end of the text box is reached. The only issue with this is that it actually adds a newline to our input. So, in order to fix it we should change END to end-1c(Thanks Bryan Oakley) The -1c deletes 1 character, while -2c would mean delete two characters, and so on.
def retrieve_input():
input = self.myText_Box.get("1.0",'end-1c')
Answer from xxmbabanexx on Stack Overflowpython - How to get the input from the Tkinter Text Widget? - Stack Overflow
Tkinter text.insert()
How to display a complete text in Tkinter GUI in python? - Stack Overflow
Edit text widgets in Tkinter
Videos
To get Tkinter input from the text box, you must add a few more attributes to the normal .get() function. If we have a text box myText_Box, then this is the method for retrieving its input.
def retrieve_input():
input = self.myText_Box.get("1.0",END)
The first part, "1.0" means that the input should be read from line one, character zero (ie: the very first character). END is an imported constant which is set to the string "end". The END part means to read until the end of the text box is reached. The only issue with this is that it actually adds a newline to our input. So, in order to fix it we should change END to end-1c(Thanks Bryan Oakley) The -1c deletes 1 character, while -2c would mean delete two characters, and so on.
def retrieve_input():
input = self.myText_Box.get("1.0",'end-1c')
Here is how I did it with python 3.5.2:
from tkinter import *
root=Tk()
def retrieve_input():
inputValue=textBox.get("1.0","end-1c")
print(inputValue)
textBox=Text(root, height=2, width=10)
textBox.pack()
buttonCommit=Button(root, height=1, width=10, text="Commit",
command=lambda: retrieve_input())
#command=lambda: retrieve_input() >>> just means do this when i press the button
buttonCommit.pack()
mainloop()
with that, when i typed "blah blah" in the text widget and pressed the button, whatever i typed got printed out. So i think that is the answer for storing user input from Text widget to variable.
So, i was trying to remake a tic-tac-toe game in python after i lost my original program, but to make things different, i wanted to make ui.
Things were going well, i followed online tutorials and the program was coming along quite nicely.
But then i just hit a big unexpected roadblock with text widgets(I hope that's their name)
I wanted to make one you couldn't edit, but while a bit searching made me find that, i couldn't find any way to edit them(as in, run a function to change it's text). I searched tons of times, tried swapping to google, but it didn't work.
Does anybody know how to do this? Here is an attempt of trying to do it myself and the error message that came up:
info.config(text="placeholder")
i tried doing the same thing as disabling editing, which is done like this:
info.config(state="disabled")
But i just returned an error:
Exception in Tkinter callback
Traceback (most recent call last):
File "file directory.py", line 1892, in __call__
return self.func(*args)
File "file directory.py", line 10, in b1
btn_pressed(1)
File "file directory.py", line 8, in btn_pressed
info.config(text="placeholder")
File "file directory.py", line 1646, in configure
return self._configure('configure', cnf, kw)
File "file directory.py", line 1636, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown option "-text"
#don't worry about that "file directory", i just replaced everything before .py with it
#also, it is located in a function caled by another function(done because i couldn't find a way to define arguments with buttons).Any help would be greatly apreciated!