0

When I search for retrieving the input from textbox, most of them created a method retrieve_input() and used that method inside the Button widget command. The retrieve_input()method is specific for one textbox. If I have several textboxes and wants to receive the inputs from all of them, do I have to create each methods for individual textboxes? Is there a way to create a general method to receive the inputs from different textboxes? or do I have to create a separate class or modules (if so how to do it?)

one of the example that I saw was How to get the input from the Tkinter Text Box Widget?

attat
  • 57
  • 9
  • It is advised to post the relevant reproducible code, input, expected output etc here and further link to external links. – LazyCoder Jul 26 '19 at 23:03

1 Answers1

2

There's nothing special you need to do. The text widget is just a python object, and the get method is just a method. You can call that method on as many text widget objects as you want.

def retrieve_input():
    data1 = text1.get("1.0", "end-1c")
    data2 = text2.get("1.0", "end-1c")
    data3 = text3.get("1.0", "end-1c")
    ...
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • When I use `retrieve_input`method and get the values, how do I send it to other methods to perform tasks(since data1,data2,data3 are all local variables, I thought they are not accessible from other methods)? – attat Jul 27 '19 at 02:48
  • @ITlearner: there’s nothing unusual you have to do, they are just python strings. Global variables, object attributes, return statements, etc. any good python tutorial will cover that subject. There is no single best way. It all depends on how you structured your program and how you want to use the values. – Bryan Oakley Jul 27 '19 at 02:54