टिंकर में, हम पैकेज का उपयोग करके टेक्स्ट विशेषताओं का उपयोग करके टेक्स्ट विजेट बना सकते हैं। हालांकि, GUI एप्लिकेशन बनाते समय, कभी-कभी हमें टेक्स्ट विजेट से इनपुट कैप्चर करने की आवश्यकता होती है।
हम .get() . का उपयोग करके टेक्स्ट विजेट में उपयोगकर्ता से इनपुट प्राप्त कर सकते हैं तरीका। हमें इनपुट रेंज निर्दिष्ट करने की आवश्यकता है जो शुरू में 1.0 से END तक होगी जो कि वर्णों को शुरू और समाप्त होने तक END तक दिखाती है।
उदाहरण
#Import tkinter library
from tkinter import *
#Create an instance of tkinter window or frame
win=Tk()
win.geometry("700x300")
def get_input():
value=my_text_box.get("1.0","end-1c")
print(value)
#Creating a text box widget
my_text_box=Text(win, height=5, width=40)
my_text_box.pack()
#Create a button for Comment
comment= Button(win, height=5, width=10, text="Comment", command=lambda: get_input())
#command=get_input() will wait for the key to press and displays the entered text
comment.pack()
win.mainloop() को प्रदर्शित करेगा। आउटपुट
उपरोक्त कोड को चलाने से एक टेक्स्टबॉक्स प्रदर्शित होगा जो उपयोगकर्ता से इनपुट स्वीकार करेगा और कंसोल पर आउटपुट प्रिंट करेगा।
