Python Forum

Full Version: Set input text from button
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,
I need to get the text of the textbox (ScrolledText) by pressing the "Find" button. At the moment the command print the text entered but I need to set a variable that contains this text.
This is the Python code


from tkinter import *
from tkinter.scrolledtext import ScrolledText

mainwin = Tk()
Label(mainwin, text="Title").grid(row=0, column=1)
Label(mainwin, text="Insert description").grid(row=1, column=0)
st = ScrolledText(mainwin, height=5); st.grid(row=1, column=1)
Button(mainwin, text="Find", command=(lambda: print(st.get(1.0, END)))).grid(row=1, column=2, sticky="EW")
Label(mainwin, text="Watson Answer:").grid(row=2, column=0)
Button(mainwin, text="Exit", command=sys.exit).grid(row=3, column=0, columnspan=3, sticky="EW")
mainwin.mainloop()

Any help will be greatly appreciated.
Thanks in advance for your kind support.
Regards,

Giovanni
Hi All,
I need to get the text of the textbox (ScrolledText) by pressing the "Find" button. At the moment the command prints the text entered but I need to set a global variable that contains this text.
This is the Python code

from tkinter import *
from tkinter.scrolledtext import ScrolledText

mainwin = Tk()
Label(mainwin, text="Title").grid(row=0, column=1)
Label(mainwin, text="Insert description").grid(row=1, column=0)
st = ScrolledText(mainwin, height=5); st.grid(row=1, column=1)
Button(mainwin, text="Find", command=(lambda: print(st.get(1.0, END)))).grid(row=1, column=2, sticky="EW")
Label(mainwin, text="Watson Answer:").grid(row=2, column=0)
Button(mainwin, text="Exit", command=sys.exit).grid(row=3, column=0, columnspan=3, sticky="EW")
mainwin.mainloop()
Any help will be greatly appreciated.
Thanks in advance for your kind support.
Regards,

Giovanni