I am wondering why is this code not working ?

 def run(self):
        QMessageBox.information(self.iface.mainWindow(),"Ok", "You pressed F7") 

NameError: global name 'QMessageBox' is not defined

I trying to make a Plugin in QGIS 2.6 using python. How can in show a message box in new QGIS 2.6 ?

  • 2
    there are two question. first and related to the subject can have the answer as: did you imported the QMessageBox from PyQt.QtGui ? – Luigi Pirelli Dec 8 '14 at 21:41

Thanks Luigi . i was missing the import thing i did nor realized it as the way the error was it sounded it says the variable has to be defined rather than the class is not recognized or missing. These people should work on error messages .

from PyQt4.QtGui import QMessageBox
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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