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
  Button to +1 in text box everytime it's clicked martyloo 2 165 Yesterday, 10:30 AM
Last Post: lillydalson
  Can't change the colour of Tk button text Pilover 6 14,909 Nov-15-2022, 10:11 PM
Last Post: woooee
  [Tkinter] Make my button text update? Skata100 1 2,066 Aug-07-2021, 05:37 AM
Last Post: deanhystad
  Updating button text based upon different variable values knoxvilles_joker 0 2,259 Apr-18-2021, 04:13 AM
Last Post: knoxvilles_joker
  tkinter | Button color text on Click Maryan 2 3,418 Oct-09-2020, 08:56 PM
Last Post: Maryan
  How to make button text bold in Tkinter? scratchmyhead 2 12,154 May-16-2020, 02:53 AM
Last Post: scratchmyhead
  [Tkinter] Text Button - How Do I Reduce The Margin? vman44 6 11,393 Apr-27-2020, 10:48 PM
Last Post: Larz60+
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 13,821 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,063 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Text after push button chano 13 5,482 Jul-05-2019, 03:10 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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