Problems with WindowProperties ()

I have the following test code

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties


class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        properties = WindowProperties()
        properties.setTitle('My Game')
	    properties.setSize(640,480)
        self.win.requestProperties(properties)
		

game = Game()
game.run()

Setting window properties I get the following error

C:\Panda3D-1.10.6-x64\samples\BennuBlocky>ppython Nuevo.py
  File "Nuevo.py", line 11
    properties.setSize(640,480)
                              ^
TabError: inconsistent use of tabs and spaces in indentation

C:\Panda3D-1.10.6-x64\samples\BennuBlocky>

It seems that it only executes the first command after instantiating WindowProperties () if I remove only one of the lines from setTitle or setSize if it works
Any suggestion Thanks

Simply put, Python is very strict about how you indent your code. You can indent with either tabs or spaces, but not both.

Specifically, it looks like you have both in the line that calls “setSize”: spaces directly before “properties”, and one or more tabs before that.

(Note that if you copied code from somewhere else into your project, that code may not have been indented in the same way as yours, potentially leading to such issues.)

Presuming that there are no other issues, simply re-indenting the affected lines should fix the problem, I imagine!

I know what you want to tell me, but if I remove the line that configures the title and do not modify anything else, if this code works
This works

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties


class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        properties = WindowProperties()
        properties.setTitle('My Game')
        self.win.requestProperties(properties)
		

game = Game()
game.run()

this also works

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties


class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        properties = WindowProperties()
        properties.setSize(640,480)
        self.win.requestProperties(properties)
		

game = Game()
game.run()

But this doesn’t work

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties


class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        properties = WindowProperties()
        properties.setSize(640,480)
		properties.setTitle('My Game')
        self.win.requestProperties(properties)
		

game = Game()
game.run()

Compare those three (try highlighting the indentation before “properties.setTitle”, for one thing): somehow, the third is ending up with a tab instead of four spaces in the third example, but not the other two.

How that’s happening I don’t know–I would guess that it’s something related to your setup, or how you’re entering this code. But one way or another, that seems to be the problem.

This doesn’t have anything to do with code, or with Panda 3d. This is about inconsistent use of tabs and spaces.
E.g. your editor is set to use spaces, and your pasted code has tabs.
If you use Sublime Text, you can do “View -> Identation -> Convert to spaces” to fix that.

1 Like

Thanks I saw it, sorry download an Editor and now I have no problems

1 Like