Bottom Page

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
sparkz_alot wrote Feb-28-2018, 04:15 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to make button text bold in Tkinter? scratchmyhead 2 109 May-16-2020, 02:53 AM
Last Post: scratchmyhead
  [Tkinter] Text Button - How Do I Reduce The Margin? vman44 6 221 Apr-27-2020, 10:48 PM
Last Post: Larz60+
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 435 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 849 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Text after push button chano 13 1,146 Jul-05-2019, 03:10 PM
Last Post: Yoriz
  [Tkinter] how to input a random entry with each button press? nadavrock 1 1,309 Jun-17-2019, 05:28 AM
Last Post: Yoriz
  Can't change the colour of Tk button text Pilover 4 3,836 Feb-27-2019, 09:02 PM
Last Post: Pilover
  [Tkinter] How to get & delete details from each input by clicking a button Vicolas 6 775 Feb-01-2019, 11:00 AM
Last Post: Vicolas
  [PyQt] Close program using Push Button with the help of input from a Message Box bhargavbn 2 1,933 Oct-30-2018, 05:09 AM
Last Post: bhargavbn
  [Tkinter] Selected radio button in push button in Tkinter prashantfunde91 1 7,779 Jun-22-2017, 05:27 PM
Last Post: DeaD_EyE

Forum Jump:


Users browsing this thread: 1 Guest(s)