# -*- coding: utf-8 -*-from PyQt4.QtCore import pyqtSignaturefrom PyQt4.QtGui import QDialogfrom PyQt4 import QtGui,QtCorefrom Ui_CreateKey import Ui_CreateKeyimport base64,uuidclass CreateKey(QDialog, Ui_CreateKey): def __init__(self, parent=None): QDialog.__init__(self, parent) self.clipboard = QtGui.QApplication.clipboard() self.setupUi(self) QtCore.QObject.connect(self.pushButton_3,QtCore.SIGNAL("clicked()"),self.clear) QtCore.QObject.connect(self.pushButton_2,QtCore.SIGNAL("clicked()"),self.getkey) @pyqtSignature("") def on_pushButton_clicked(self): key = base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes) self.textBrowser.append(str(key)) @pyqtSignature("") def clear(self): self.textBrowser.clear() @pyqtSignature("") def getkey(self): self.clipboard.setText(self.textBrowser.toPlainText().split('\n')[-1])if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) ui = CreateKey() ui.show() sys.exit(app.exec_())