Seite 1 von 1

Fehlermeldung "inconsistent use of tabs and spaces in indentation"

Verfasst: Donnerstag 20. Oktober 2016, 11:02
von rusb
Hallo, ich hab seit gestern angefangen mit Python zu programmieren. Ich erhalte immer folgenden Fehler beim ausführen meines Codes:

"inconsistent use of tabs and spaces in indentation"

Code: Alles auswählen


from Tkinter import *
import tkFont
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, GPIO.LOW)

win = Tk()

myFont = tkFont.Font(family = 'Helvetica', size = 36, weight = 'bold')

def ledON():
	print("LED button pressed")
	if GPIO.input(40) :
 		GPIO.output(40,GPIO.LOW)
		ledButton["text"] = ("LED ON")   # hier wird der Fehler angezeigt
	else:
		GPIO.output(40,GPIO.HIGH)               
                ledButton["text"] = ("LED OF")

def exitProgram():
	print("Exit Button pressed")
        GPIO.cleanup()
	win.quit()	


win.title("First GUI")
win.geometry('800x480')

exitButton  = Button(win, text = "Exit", font = myFont, command = exitProgram, height =2 , width = 6) 
exitButton.pack(side = BOTTOM)

ledButton = Button(win, text = "LED ON", font = myFont, command = ledON, height = 2, width =8 )
ledButton.pack()

mainloop()

Kann mir jemand erklören was ich das machen soll?

Viele Grüe

Re: Fehlermeldung "inconsistent use of tabs and spaces in indentation"

Verfasst: Donnerstag 20. Oktober 2016, 11:18
von DasIch
Python beschwert sich darüber dass du sowohl Tabs als auch Leerzeichen zur Einrückung verwendest. Du kannst nur eins von beiden verwenden und du solltest nur Leerzeichen verwenden.

Re: Fehlermeldung "inconsistent use of tabs and spaces in indentation"

Verfasst: Donnerstag 20. Oktober 2016, 12:22
von Sirius3
@rusb: mit der Code-Formatierung im Forum siehst Du auch schön, dass mit Zeile 21 und Zeile 25 etwas nicht stimmt. Nimm immer 4 Leerzeichen pro Einrückebene und ein guter Editor sollte die Möglichkeit haben, dass das automatisch passiert, wenn man die Tab-Taste drückt.