def dropEvent(self, event): obj = event.mimeData().data('application/py_instance') try: lbl = obj[0].label except (IndexError, AttributeError): lbl = 'x' lbl = as_variable_name(lbl) var, ok = QtWidgets.QInputDialog.getText(self, "Choose a variable name", "Choose a variable name", text=lbl) if ok: # unpack single-item lists for convenience if isinstance(obj, list) and len(obj) == 1: obj = obj[0] var = {as_variable_name(str(var)): obj} self.update_namespace(var) event.accept() else: event.ignore()