def add_srv(self, address, ports): for host in self.hosts: if address == host.address and ports == host.ports: # We already know this server, skip return host = QTreeWidgetItem(self.serverview) host.address = address host.ports = ports host.hostname = 'This computer' if address == get_ownip() else address host.setText(0, host.hostname) host.setText(1, '{},{}'.format(*ports)) self.hosts.append(host)