After running several hundred lines of commands (and getting their subsequent error statements...), it is nice to be able to clear out the console window and start clean.

In the Python Console window in QGIS, I would like to clear it out. If I close it and then open it again, the buffer is still retained. If I 'select all' and delete the content, I don't get a prompt and can't do anything to get one back.

Any suggestions on how to clear out the scroll back buffer?

  • If I may ask: Why? I don't think that's implemented but you can open an enhancement request. (Be prepared to answer the previous question though.)
    – underdark
    Commented Sep 28, 2010 at 21:39
  • @underdark: So that you know how far to scroll back after you execute the next command.
    – relet
    Commented Sep 29, 2010 at 6:43
  • @underdark I believe that you are right. I guess that I had two things in mind. First to just get a clean window, but that can just be accomplished with a bunch of /n or returns. The second thing I was thinking of was del'ing all of the variables/objects that had been created through the console. I was trying to test some code, but it was affected by an existing value for a shared variable. I guess that this is the difference between running a standalone shell vs opening and closing the console in an application that continues to run.
    – DavidF
    Commented Sep 29, 2010 at 14:01
  • I have wondered about this too, you could open console.py file in the Qgis folder which has some python stuff for the console, like font etc and hack some code in to clear the buffer. I was going to do this but just never got around to it.
    – Nathan W
    Commented Oct 3, 2010 at 8:19
  • 3
    Despite this one being the original question, voting to close as a duplicate of Clearing QGIS Python console with pyQGIS which has more up to date code answers. Commented May 9 at 1:59

2 Answers 2


Ok, so I have been playing around with QGIS console.py to see if you can do this yourself and it turns out to be pretty easier.

Open up console.py which, if you have installed using OSGeo4W, is in C:\OSGeo4W\apps\qgis\python\qgis. Then look for the python method called def entered(self): and replace it with the following:

def entered(self):
    self.cursor.movePosition(QTextCursor.End, QTextCursor.MoveAnchor)
    command = unicode(self.currentCommand())
    if command == 'clear':

also add the following method after the entered method:

def clearConsole(self):
      self.insertTaggedText("To access Quantum GIS environment from this console\n"
                          "use qgis.utils.iface object (instance of QgisInterface class).\n"
              "\n", ConsoleHighlighter.INIT)

Save console.py and close, and restart QGIS.

The clearConsole will clear out the console window and return it the way it was when you first open it when the clear command is entered into the window.

However this doesn't clear the history, or restart any variables but I wouldn't want it to if I was using it.

Hope this helps with what you need.

EDIT: As of V1.7 this is a built in feature of the Python console. Just call qgis.console.clearConsole() in the Python console to clear it.

  • 2
    Well done Nathan!
    – DavidF
    Commented Oct 5, 2010 at 14:51
  • 1
    @Nathan: Using QGIS 2.6.0, I am trying to clear the console from within my plugin [to aid debug, by printing, basically to auto-clear the console as I rerun the code]. I've looked for the qgis.console.clearConsole() code within the API, and tried variants of the line without success, let alone trying to decide what import[s] to add to my code. To the best of my search, I don't see that object or use -- Am I misunderstanding your edit of May 2011, for your suggestion for "clearConsole"?
    – John
    Commented Nov 19, 2014 at 16:02
  • I do see a def clearConsole within a python module called console_output.py at line 199 but, having found it, I have no idea how to access/execute it. Nor do I know how to force the 'action' that appears within the console.py module, relating to clearing the console. I'm still stymied....
    – John
    Commented Nov 19, 2014 at 17:41
  • 2
    Don't write to the console when trying to debug. Use QgsMessageLog.logMessage("message", "title") to write to the log window.
    – Nathan W
    Commented Nov 19, 2014 at 23:12
  • 1
    "Just call qgis.console.clearConsole()': Apparently gone in 3.14: AttributeError: module 'qgis' has no attribute 'console'.
    – mins
    Commented Feb 21, 2022 at 13:04

In QGIS version 3.22, there is a button on the top left of the console that clears it.

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.