Improving the 'title' of a second window in Python Mode

Thanks to GoToLoop and others who discussed it here and on the earlier forums, I know I can make a sketch with more than one window like this:

def setup():
    size(200, 300)
    second_window = OtherWindow()  
    
def draw():
    background(0)
    ellipse(mouseX, mouseY, 10, 10)


class OtherWindow(PApplet):  
        
    def __init__(self):
        switches = ('--sketch-path=' + sketchPath(), '')
        PApplet.runSketch(switches, self)  
        
    def settings(self):
        self.size(300, 200)
        
    def draw(self):  
        self.background(255)
        self.fill(0)
        self.rect(self.mouseX, self.mouseY, 10, 10)

I would like to set the title of my second window (the defaut is an ugly "_main_$OtherWindow$"), but I can’t find the surface.setTitle(" ") method for it.

Any clues?

2 Likes

Use this.surface.setTitle() and second_window.surface.setTitle(). When I modify your sketch, this works:

def setup():
    size(200, 300)
    this.surface.setTitle("1")
    second_window = OtherWindow()
    second_window.surface.setTitle("2")

Or, from inside the object, use self.surface.setTitle():

    def __init__(self):
        switches = ('--sketch-path=' + sketchPath(), '')
        PApplet.runSketch(switches, self)
        self.surface.setTitle("3")

Weirdly self.frame.setTitle() also works only from within the object – perhaps legacy syntax, or something about java.awt…

1 Like

Or self.surface.title = 'Sketch Title'

2 Likes

I guess I’m getting crazy or something!
I swear I tried self.surface.setTitle() before and it didn’t work!
Thanks!