Reputation: 115
I am trying to create a statement which checks whether a TextBox is empty, if that is not the case and the TextBox is not empty, then I want the textBox to refresh itself.
I have tried the following:
if (len(self.txtBox.get() != 0)):
self.txtBox.update()
print "Textbox was not empty"
However I am given the following error, 'Type Error: get() takes at least 2 arguments, 1 given '. I know the error indicates that I should pass an argument in the get function, however I have seen code snippets using the get() function without passing any arguments, and either way I do not know what argument I should pass.
Any help would be greatly appreciated.
Upvotes: 2
Views: 5389
Reputation: 385830
There is no widget called a "TextBox", so I don't know if you're talking about an Entry widget or a Text widget. The get
method of the entry widget can be called without parameters, but the get
method of the text widget requires two parameters. The two parameters are the starting and ending points of a region.
To get everything in a text widget, you should do it like this:
self.txtBox.get("1.0", "end-1c")
The "1.0"
represents the first character, and "end-1c"
represents the last character ("end") minus one character ("-1c") which will ignore the trailing newline that is always added by tkinter itself.
Upvotes: 3
Reputation: 37003
This old message from the python-tutor
list might help. The two parameters are bizarre (to my mind: I am not a Tk
expert) pointers, similar to string slicing but with the "pointers" being decimal numbers where the integer portion specifies the line and the decimal places specify the character numbers.
Upvotes: 0