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()