Check if a tkinter.Text is empty

0

I'm trying to create a simple notepad, but I have one small problem: when I try to see if the text of an object Text is empty or not:

if text_area.get(0.0, tkinter.END) != "":
    print("Text não vazio") # é sempre executado

When I try to use the len function to control the length of the text, it returns 1.

What is this default character after all? My solution would be to control the length of the text with 1 (or maybe better, if the length is greater than 1), and if it returns True, it means that it is "empty".

Now, why does Python , or rather the tkinter library provide an end-of-text indicator, ie tkinter.END , not start? Why do I have to put 0.0 (and not tkinter.START )?

(Compared for example to the Java language, and in particular to its Swing bookstore, the tkinter bookstore is really unintuitive, even frankly frankly)

    
asked by anonymous 24.09.2014 / 00:14

1 answer

1

Try the following:

if text_area.get(1.0, tkinter.END) != "":
    print("Text não vazio")

1.0 Meaning row 1 , column 0 , rows are indexed from 1 and columns are indexed in 0 .

At the following link ( Text widget indices ) describes some ways to work with indexes in widgets using TKinter .

    
24.09.2014 / 00:26