#!/usr/bin/env python
#GENERATE A NEW SCRIPT 
def Creation():
fichero=open('generator.py','w')
fichero.close()
def Save():
fichero=open('generator.py','a')
fichero.write('from PyQt4.QtGui import *\n')
fichero.write('import sys\n')
fichero.write('class Window(QWidget):\n')
fichero.write('\tdef __init__(self,parent=None):\n')
fichero.write('\t\tQWidget.__init__(self)\n')
fichero.write('\t\tself.label=QLabel("Show a message")\n')
fichero.write('\t\tself.lineEdit=QLineEdit()\n')
fichero.write('\t\tself.lineEdit.setPlaceholderText("Write Here")\n')
fichero.write('\t\tself.button=QPushButton("Show message")\n') 
fichero.write('\t\tself.layout=QVBoxLayout()\n')
fichero.write('\t\tself.layout.addWidget(self.label)\n')
fichero.write('\t\tself.layout.addWidget(self.lineEdit)\n')
fichero.write('\t\tself.layout.addWidget(self.button)\n')
fichero.write('\t\tself.setLayout(self.layout)\n')
fichero.write('\t\tself.button.clicked.connect(self.Mensaje)\n')
fichero.write('\tdef Mensaje(self):\n')
fichero.write('\t\tmensaje=QMessageBox.information(self,"mensaje",self.lineEdit.text())\n')
fichero.write('if __name__=="__main__":\n')
fichero.write('\ttry:\n')
fichero.write('\t\tapp=QApplication(sys.argv)\n')
fichero.write('\t\tventana=Window()\n')
fichero.write('\t\tventana.show()\n')
fichero.write('\t\tsys.exit(app.exec_())\n')
fichero.write('\texcept SystemExit:\n')
fichero.write('\t\tpass\n')
fichero.close()
n=raw_input("Do you wish create a new script [Y/N]?: ")
if n=='Y' or n=='y':
Creation()
Save()
print("the file has been created")
raw_input()
else:
print("file doesn't created")
raw_input()

Create scriptGenerator.py