Hello all.

For getting the values from text field, we use ".get" function.
I would like to get all the contents from the text area.
What is the function to use.

hey bhanu,

yes you could use

text.get(params)

what are these params?
You have to define what you want to read in your text. The syntax is:

text.get(position1,position2)

some possible positions:
+count chars count characters after the current position
-count chars count characters before the current position

+count lines count lines after the current position
-count lines count lines before the current position

wordstart the first character of the word, which contains the character of the current position
wordend the character AFTER (not the last character) the last character of the word, which contains the character of the current position

linestart the first character of the line, that contains the character of the current position
lineend the LAST character (different from wordend!) of the line, that contains the character of the current position

example: if you want to read one line from the current position:

extracttext= text.get(linestart,lineend)

Hope that will help you a little bit.
greetings
Mearah

Like this example, we are using the functions for getting the values of text field.
Any similar functions for text areas?

def CreateWidgets(self):
self.lbText1 = Label(self, text="User ID:")
self.lbText1.grid(row=0, column=0)

"""Create the Entry, set it to be a bit wider"""
self.enText1 = Entry(self)
self.enText1.grid(row=0, column=1, columnspan=3)

self.lbText2 = Label(self, text="password:")
self.lbText2.grid(row=1, column=0)

self.enText2 = Entry(self,show="*")
self.enText2.grid(row=1, column=1, columnspan=3)

def Display(self):
name = self.enText1.get()
password = self.enText2.get()

hm, as I see you do not have a text area, but a Lable. That is quite different. In the Lable you put some predefined text you want to show the user, maybe to explain the use or name of an inputarea.
The textfield is something you provide to the user to fill in text on his own.

Try something like that (please fill in your code with the code-tags, so it is better to read

import Tkinter  #get the module
from Tkconstants import *  #best is you have a look at the documentation of this, because then you can choose from all of the functions and find excactly what you need)

mywindow=Tkinter.Tk()   # there you can but everything in
text = Tkinter.Text(mywindow, width=30, height=6) #here you call the textfield, the user could write in, the first parameter is the parent to which it belongs, as we want to put everything in mywindow, we choose that, then there are several possible parameters, here I use params to size the textfield)
...
#here you can put something else concerning the window, maybe you want to write some predefined things in your window:

text.pack()  #in the end put your textfield in it's place
tk.mainloop()

to test the text.get(parms) function, maybe you also put a button under the textfield, and say it shall print what the user wrote.

Mea

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.