def toggle(self):
        """
        Toggle the visibility of associated window. Either show() or hide().
        """
        if self.window.has_focus:
            self.hide()
        elif self.shown and self.visible:
            win = self.window
            win.bring_to_front()
            win.focus(warp=True)
            self.shown = True
        else:
            self.show()

        Toggle the visibility of associated window. Either show() or hide().
        
libqtile/scratchpad.py