-3

I am doing OOP code and I have some problem, I have searched the internet and supposedly I am doing it right. But it gives me an error and does not execute me.

I have this:

from tkinter import *
from tkinter import ttk
import pymysql
from tkinter import messagebox as MessageBox
from tkinter import scrolledtext as st

class Aplicacion:
    def __init__(self):
        self.ventana1 = Tk()
        self.ventana1.title("Login")
        self.ventana1.geometry("400x400")
        self.imagenLogo = PhotoImage(file="logo2.png")
        self.divLogo = Label(self.ventana1, image=self.imagenLogo)
        self.divLogo.place(x=93, y=0)
        self.x_ventana = self.ventana1.winfo_screenwidth() // 2 - 300 // 2
        self.y_ventana = self.ventana1.winfo_screenheight() // 2 - 300 // 2
        self.posicion = str(300) + "x" + str(300) + "+" + str(self.x_ventana) + "+" + str(self.y_ventana)
        self.ventana1.geometry(self.posicion)
        self.ventana1.resizable(0,0)
        self.formulario()
        self.ventana1.mainloop()

    def formulario(self):
        ### Formulario de Entrada ###
        self.label1 = ttk.Label(text="Usuario:").place(x=50, y=110)


Ventana = Aplicacion()

What I want is to insert a tkinter Label into the viewport from a function. But it gives me this error in sublime text:

File "/Users/tomas/Downloads/DonMovil/objetos.py", line 29
    self.label1 = ttk.Label(text="Usuario:").place(x=50, y=110)
TabError: inconsistent use of tabs and spaces in indentation
[Finished in 47ms with exit code 1]
[cmd: ['python3', '-u', '/Users/tomas/Downloads/DonMovil/objetos.py']]
[dir: /Users/tomas/Downloads/DonMovil]
[path: /Library/Frameworks/Python.framework/Versions/3.10/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin]
martineau
  • 119,623
  • 25
  • 170
  • 301
Tomas
  • 1
  • 3
  • 3
    This error means that you have used tabs to indent some of your code, and spaces to indent the rest. To run a Python script, you need to use either only tabs or spaces to indent. [PEP8](https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces) recommends using 4 spaces as indentation. – jezza_99 Jan 20 '22 at 19:29
  • 1
    In sublime, you can convert indentation by clicking either "Tab Size: X" or "Spaces: X" on the bottom right and select "Convert indentation to spaces" (and change to indent with spaces if not already) – jezza_99 Jan 20 '22 at 19:31
  • 1
    It doesn't look like you've done any research. You should search this site for the error message "TabError: inconsistent use of tabs and spaces in indentation" – Bryan Oakley Jan 20 '22 at 20:04

1 Answers1

0

You need to fix indentation by using either 4 spaces or a tab. You can't interchange between them or it won't work. I don't know why but that is the way it is. I recommend shift tabbing them back to start and then using tab until the indentation is right. Get rid of spaces for indentations too. Make sure to research by searching (copying and pasting) the exact error code you got (I.E. "TabError: inconsistent use of tabs and spaces in indentation") as @Bryan Oakley suggested.

TRCK
  • 231
  • 3
  • 12