Python Forum
Set input text from button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Set input text from button
#1
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
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to update label text using a grid button. Edward_ 7 1,580 Dec-18-2024, 03:05 AM
Last Post: Edward_
  [Tkinter] Text input OK on Windows, not working on linux Ota 3 1,177 Sep-19-2024, 12:02 AM
Last Post: Ota
  popup, text input with two readable buttons ethompson 7 1,954 Aug-28-2024, 03:40 AM
Last Post: deanhystad
  Button to +1 in text box everytime it's clicked martyloo 1 1,373 May-01-2024, 02:32 PM
Last Post: Axel_Erfurt
  Can't change the colour of Tk button text Pilover 6 19,856 Nov-15-2022, 10:11 PM
Last Post: woooee
  [Tkinter] Make my button text update? Skata100 1 2,711 Aug-07-2021, 05:37 AM
Last Post: deanhystad
  Updating button text based upon different variable values knoxvilles_joker 0 2,866 Apr-18-2021, 04:13 AM
Last Post: knoxvilles_joker
  tkinter | Button color text on Click Maryan 2 4,381 Oct-09-2020, 08:56 PM
Last Post: Maryan
  How to make button text bold in Tkinter? scratchmyhead 2 14,635 May-16-2020, 02:53 AM
Last Post: scratchmyhead
  [Tkinter] Text Button - How Do I Reduce The Margin? vman44 6 15,829 Apr-27-2020, 10:48 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020