Pygame'de Girinti Hatası (vsc)

Merhabalar ben visual studio code ile kodlarım yazıyorum ve dün bir hata ile karşılaştım kısa süreliğine düzeldi ama yine oldu. Girintiyi tab yerine 4 boşluk ile yapmayı denedim en başta düzelmişti ama sonra tekrardan hata verdi.

İlk Hali:
hata

For döngüsünü yukarı aldıktan sonra:
resim_2023-01-05_221704798

Tüm Kodlar:

import pygame, sys
import random
import ctypes
myappid = 'mycompany.myproduct.subproduct.version'
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

pygame.init()

# ekran ayarları
width = 900
heigh = 600
icon = pygame.image.load("icon.png")
main_win = pygame.display.set_mode((width,heigh))
pygame.display.set_caption("Oyun")
pygame.display.set_icon(icon)

# gömülü sınıflar
class TextButton():
	def __init__(self, x, y, text, fsize = 20, csize = 2, x_ayar = 3, y_ayar = 4, uzunluk_ayar = 6, yukseklik_ayar = 5):
		font = pygame.font.SysFont("calibri", fsize)		
		self.text = font.render(text, True, (255,255,255))
		self.rect = self.text.get_rect()
		self.rect_width = self.text.get_width()
		self.rect_heigh = self.text.get_height()
		self.rect.topleft = (x, y)
		self.cerceve = pygame.draw.rect(main_win, (255,255,255), (x - x_ayar, y- y_ayar, self.rect_width + uzunluk_ayar, self.rect_heigh + yukseklik_ayar), csize)
		self.clicked = False

	def draw(self, surface):
		action = False
		#get mouse position
		pos = pygame.mouse.get_pos()

		#check mouseover and clicked conditions
		if self.rect.collidepoint(pos):
			if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False:
				self.clicked = True
				action = True

		if pygame.mouse.get_pressed()[0] == 0:
			self.clicked = False

		#draw button on screen
		surface.blit(self.text, (self.rect.x, self.rect.y))

		return action
class ImageButton():
	def __init__(self, x, y, image, scale):
		width = image.get_width()
		height = image.get_height()
		self.image = pygame.transform.scale(image, (int(width * scale), int(height * scale)))
		self.rect = self.image.get_rect()
		self.rect.topleft = (x, y)
		self.clicked = False

	def draw(self, surface):
		action = False
		#get mouse position
		pos = pygame.mouse.get_pos()

		#check mouseover and clicked conditions
		if self.rect.collidepoint(pos):
			if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False:
				self.clicked = True
				action = True

		if pygame.mouse.get_pressed()[0] == 0:
			self.clicked = False

		#draw button on screen
		surface.blit(self.image, (self.rect.x, self.rect.y))

		return action

# gömülü fonksiyonlar
def yaz(text, x, y, renk, size = 15, font = "calibri"):
	font = pygame.font.SysFont(font, size)
	yazi = font.render(text, True, renk)
	main_win.blit(yazi, (x, y))

# global değişkenler 
clock = pygame.time.Clock()

# resimler
#dugme = pygame.image.load("assets/cikis_dugme.png")

bg = pygame.image.load("main_world.png")
bg = pygame.transform.scale(bg, (width, heigh))

# düğmeler
#saldir_tus = ImageButton(20,20,dugme,1)
yazi_tus = TextButton(20,350,"Saldır", fsize= 20, csize= 3)

# döngü 
loop = True
while loop:
    
    main_win.blit(bg, (0,0))
    
    # tuş kontrol
    #if saldir_tus.draw(main_win):
    #    print("oldu")
    if yazi_tus.draw(main_win):
    	print("yine oldu")
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            loop = False
        if event.type == pygame.KEYDOWN:
            pass	

    pygame.display.update()	
    clock.tick(60)
pygame.quit()
sys.exit()

Merhaba sorunun çözümünü biraz araştırarak buldum. Bu hatayı alan kodunuz açıkken F1 veya ctrl+shift+p tuşlarına basarsanız bir ekran açılacaktır buraya sadece indent yazdığınızda karşınıza ilk iki sırada “convert indentation to tabs” ve “conert indentation to space” çıkar ben burada ilk seçeneğe yani tabs olana bastım çünkü ben normalde tab tuşu ile girinti veriyorum siz space olanı da seçebilirsiniz. Bunları yaptığımda sorun çözüldü.

Not: Ben editor olarak vsc kullanıyorum diğer editorlerde bu sorun çözülmeyebilir.

Çözümü Öğrendiğim Kaynak: visual studio code - VSCode Extension to fix inconsistent tab issue of Python - Stack Overflow

1 Beğeni