Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7786713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:27:44+00:00 2026-06-01T20:27:44+00:00

I’m having a problem trying to do a very simple user interface. I made

  • 0

I’m having a problem trying to do a very simple user interface. I made my UI with Qt Designer, and then with pyuic4 I got my python code. Then I programmed the function I needed, and compiled with Eclipse IDE.

The code I got from pyuic4 is:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'Dni.ui'
#
# Created: Sat Apr 14 02:44:34 2012
#      by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(371, 217)
        Dialog.setMinimumSize(QtCore.QSize(371, 217))
        self.layoutWidget = QtGui.QWidget(Dialog)
        self.layoutWidget.setGeometry(QtCore.QRect(30, 30, 311, 151))
        self.layoutWidget.setObjectName(_fromUtf8("layoutWidget"))
        self.gridLayout = QtGui.QGridLayout(self.layoutWidget)
        self.gridLayout.setMargin(0)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
        self.label = QtGui.QLabel(self.layoutWidget)
        self.label.setObjectName(_fromUtf8("label"))
        self.horizontalLayout.addWidget(self.label)
        self.entrada = QtGui.QLineEdit(self.layoutWidget)
        self.entrada.setObjectName(_fromUtf8("entrada"))
        self.horizontalLayout.addWidget(self.entrada)
        self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1)
        self.boton = QtGui.QPushButton(self.layoutWidget)
        self.boton.setObjectName(_fromUtf8("boton"))
        self.gridLayout.addWidget(self.boton, 1, 0, 1, 1)
        self.horizontalLayout_2 = QtGui.QHBoxLayout()
        self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
        self.label_3 = QtGui.QLabel(self.layoutWidget)
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.horizontalLayout_2.addWidget(self.label_3)
        self.salida = QtGui.QLineEdit(self.layoutWidget)
        self.salida.setObjectName(_fromUtf8("salida"))
        self.horizontalLayout_2.addWidget(self.salida)
        self.gridLayout.addLayout(self.horizontalLayout_2, 2, 0, 1, 1)
        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("Dialog", "Introduzca su DNI", None, QtGui.QApplication.UnicodeUTF8))
        self.boton.setText(QtGui.QApplication.translate("Dialog", "Hallar NIF", None, QtGui.QApplication.UnicodeUTF8))
        self.label_3.setText(QtGui.QApplication.translate("Dialog", "NIF:", None, QtGui.QApplication.UnicodeUTF8))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Dialog = QtGui.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())

And the code I made with the function I need:

from Dni import Ui_Dialog
from PyQt4 import QtCore, QtGui

LETRADNI = {0:'T', 1:'R', 2:'W', 3:'A', 4:'G', 5:'M', 6:'Y', 7:'F', 8:'P', 9:'D', 10:'X', 11:'B', 12:'N',
            13: 'J', 14:'Z', 15:'S', 16:'Q', 17:'V', 18:'H', 19:'L', 20:'C', 21:'K', 22:'E'}


# Se hereda de la clase QtGui.QMainWindow
class Principal(QtGui.QMainWindow):
    # Se define el constructor de la clase __init__
    def __init__(self):
        # Se llama al constructor de la clase padre
        QtGui.QMainWindow.__init__(self)

        # Se crea la instancia de Ui_Dialog
        self.ventana = Ui_Dialog()
        self.ventana.setupUi(self)

        # Se conectan las señales con los slots
        self.connect(self.ventana.boton,QtCore.SIGNAL('clicked()'), self.letradni)


def Calcula_letra_dni(dni):
    '''Función Calcula_letra_dni:

        Funcionamiento:

            La función recibe el valor entero dni. Posteriormente calculará el resto de la división
            por 23. Éste número se buscará en el diccionario 'LETRADNI' para obtener la letra correspondiente
            a ese DNI.

        Argumentos

            dni -- número del documento nacional de identidad (int)

        Devuelve:

            Una cadena (string) -- DNI + letra preparado para salida por pantalla
    '''
    #if len(str(dni))>8 & len(str(dni))<7:
    #    raise ValueError('El dni debe tener entre 7 y 8 cifras')

    num_letra = dni % 23.0

    letra = LETRADNI[num_letra]

    return '{0}-{1}'.format(dni,letra)


def letradni(self):
    self.ventana.salida.setText(Calcula_letra_dni(self.ventana.entrada.text()))

The first one compiles and runs, it shows my ui perfectly.

Compiling the second one I get an error that says:

Description                                 Resource  Path  Location   Type
Undefined variable from import: QString Dni.py    /Dni  line 18    PyDev Problem

Can anyone help me?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:27:45+00:00Added an answer on June 1, 2026 at 8:27 pm

    First off, I think your actual listed problem is related to Eclipse, pydev, and your projects PYTHONPATH. Review this to make sure you have properly set up everything and included PyQt4 in your pythonpath:
    http://popdevelop.com/2010/04/setting-up-ide-and-creating-a-cross-platform-qt-python-gui-application/

    After that, you seem to have some problems with your code beyond what you have mentioned…

    First you define Principal class, then a Calcula_letra_dni function, but then you are defining what looks like a class instance method letradni which should be part of Principal:

    class Principal(QtGui.QMainWindow):
        # Se define el constructor de la clase __init__
        def __init__(self):
            ...
    
        def letradni(self):
            ...
    
    
    def Calcula_letra_dni(dni):
        ...
    

    Then it looks like you will raise an exception when you try to do math on a string (thanks @Avaris) and float:
    num_letra = dni % 23.0

    You should probably convert that string to a float first: num_letra = float(dni) % 23.0

    And finally, I think you also forgot to define a main for your application. You have the one that is autogenerated in your Dni.py, but you didn’t write one for your actual entry point script:

    if __name__ == "__main__":
        import sys
        app = QtGui.QApplication(sys.argv)
        form = Principal()
        form.show()
        sys.exit(app.exec_())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.