Truman9084
Truman9084

Reputation: 11

Problem in Spyder "inconsistent use of tabs and spaces in indentation"

I have a problem when I want to run my script, I'm using Anaconda Spyder with python 3.8, Its my first time using Tkinter and grid, I can't find the problem. The message from Spyder console is:

     self.tabla0.grid(row=6, column=0, columnspan=2)
                                                   ^
TabError: inconsistent use of tabs and spaces in indentation

Somebody could help me? I'm desperate :(

from tkinter import ttk
from tkinter import *
from tkinter import messagebox as message

class APP:
    def __init__(self, Ventana):
        self.wind=Ventana
        self.wind.title("APP Att")
        
        frame =LabelFrame(self.wind, text="Registra datos ") 
        frame.grid(row=0, column=0, columnspan=3,ipadx=20)
        
        
        Label(frame, text="Nombre" ).grid(row=1, column=1)
        self.nombre = Entry(frame)
        self.nombre.grid(row=1, column=2, pady=5)
        
        Label(frame, text="Puesto" ).grid(row=2, column=1)
        self.puesto = Entry(frame)
        self.puesto.grid(row=2, column=2, pady=5)
        
        Label(frame, text="Telefono" ).grid(row=3, column=1)
        self.tel = Entry(frame)
        self.tel.grid(row=3, column=2, pady=5)
        
        Label(frame, text="Correo" ).grid(row=4, column=1)
        self.corr = Entry(frame)
        self.corr.grid(row=4, column=2, pady=5)
        
        ttk.Button(frame, text="Salvar").grid(row=5, columnspan=3)
        
        
        self.tabla0 = ttk.Treeview(height=10, column=4)
        self.tabla0.grid(row=6, column=0, columnspan=2)  #HERE IS THE PROBLEM
        self.tabla0.heading("#0",text="Nombre",anchor='center')
        self.tabla0.heading("#1",text="Puesto",anchor='center')
        self.tabla0.heading("#2",text="Telefono",anchor='center')
        self.tabla0.heading("#3",text="Correo",anchor='center')
        self.mostrar()
   
        
if __name__=="__main__":
    root=Tk()
    MiApp=APP(root)
    root.mainloop() 

Upvotes: 1

Views: 4623

Answers (2)

Nathan
Nathan

Reputation: 21

I experienced this issue after upgrading spyder versions. Copy pasting the code into notepad and then copy pasting back again fixed it for me.

Upvotes: 2

Graham
Graham

Reputation: 107

The issue is that you have most likely copied this from someone else repo/source and pasted it into spyder. In doing so, Spyder doesn't account for the correct formatting, namely indentations, and instead pastes them as blank spaces.

You will notice that if you delete the blank space and correctly add an indent the error will only move down a row.

To view where Spyder has added the wrong formatting, go to Preferences > Editor and select; "show blank spaces" and "show indent guides".

Delete the blank spaces and add indents. Job done.

Upvotes: 3

Related Questions