0

I was searching for how to retrieve inputs from Tkinter Textbox widget and I found this. After reading the answer and following the code, I got some few questions.

1st In the answer, most of them they 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?)

2nd I tried the code with pycharm but it did not show the input value in the console even after I pressed 'ok' button
Answered with Why is Button parameter “command” executed when declared?

3rd if I get rid of "1.0", "end-1c" it shows TypeError: get() missing 1 required positional argument: 'index1'. When I look up that error, it says that I did not initiate the starting value. But I saw many other examples in the internet that did not put any parameters inside the get(). Also I thought if I do not put any parameters, the get() will automatically get the first characters. Which part am I understanding wrong?

Thank you Reblochon Masque for giving me the link for answer 2. But I still don't get question 1 and 3

from tkinter import *

def main():
    root = Tk()
    root.title("Youtube Converter")

def retrieve_input():
    inputValue = textBox.get("1.0", "end-1c")
    print(inputValue)

label = Label(root, text="type url")
label.grid(row=0, column=0)

textBox = Text(root, height=2, width=10)
textBox.grid(row=0, column=1)

btn = Button(root, height = 1, width=15, text = "ok", command = retrieve_input())
btn.grid(row=1, column=1)


root.mainloop()
attat
  • 57
  • 9
  • 1
    remove the parenthesis after `retrieve_input`: `btn = Button(root, height = 1, width=15, text = "ok", command = retrieve_input)` <-- here – Reblochon Masque Jul 26 '19 at 13:36
  • Thank you Reblochon Masque for the answer. May you also help me answer Q1 and 2? – attat Jul 26 '19 at 13:53
  • 1
    3rd question: you are confusing `tk.Entry` with `tk.Text `; the former does not require indexing of the values to be retrieved. The first question requires more than a comment to answer - please ask a new question, and feel free to ping me when it is done. – Reblochon Masque Jul 26 '19 at 14:01
  • I posted the question but did not know how to ping you from there. So I leave a comment @ReblochonMasque. – attat Jul 26 '19 at 22:56
  • https://stackoverflow.com/questions/57227812/about-retrieving-method-in-tkinter the link – attat Jul 27 '19 at 02:26
  • Thank you - @BrianOakley correctly replied already, you should upvote and accept his answer. – Reblochon Masque Jul 27 '19 at 02:28

0 Answers0