Skip to main content
Commonmark migration
Origen Enlace

##### Python >= 3.4 import pathlib from PyQt5.QtWidgets import QMainWindow,QApplication from PyQt5 import QtCore from PyQt5 import uic

# Python >= 3.4

import pathlib
from PyQt5.QtWidgets import QMainWindow,QApplication
from PyQt5 import QtCore
from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = pathlib.Path(__file__).parent
        uic.loadUi(mod_path / "ui_files/FirstUser.ui", self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

##### Python < 3.4 import os from PyQt5.QtWidgets import QMainWindow,QApplication from PyQt5 import QtCore from PyQt5 import uic

# Python < 3.4

import os
from PyQt5.QtWidgets import QMainWindow,QApplication
from PyQt5 import QtCore
from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = os.path.dirname(__file__)
        uic.loadUi(os.path.join(mod_path, "ui_files/FirstUser.ui"), self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

##### Python >= 3.4 import inspect import pathlib

# Python >= 3.4

import inspect
import pathlib

filename = inspect.getframeinfo(inspect.currentframe()).filename
mod_path = pathlib.Path(filename).resolve().parent
uic.loadUi(mod_path / "ui_files/FirstUser.ui", self)

##### Python < 3.4 import inspect import os

# Python < 3.4

import inspect
import os

filename = inspect.getframeinfo(inspect.currentframe()).filename
mod_path = os.path.dirname(os.path.abspath(filename))
uic.loadUi(os.path.join(mod_path, "ui_files/FirstUser.ui"), self)

##### Python >= 3.4 import pathlib from PyQt5.QtWidgets import QMainWindow,QApplication from PyQt5 import QtCore from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = pathlib.Path(__file__).parent
        uic.loadUi(mod_path / "ui_files/FirstUser.ui", self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

##### Python < 3.4 import os from PyQt5.QtWidgets import QMainWindow,QApplication from PyQt5 import QtCore from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = os.path.dirname(__file__)
        uic.loadUi(os.path.join(mod_path, "ui_files/FirstUser.ui"), self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

##### Python >= 3.4 import inspect import pathlib

filename = inspect.getframeinfo(inspect.currentframe()).filename
mod_path = pathlib.Path(filename).resolve().parent
uic.loadUi(mod_path / "ui_files/FirstUser.ui", self)

##### Python < 3.4 import inspect import os

filename = inspect.getframeinfo(inspect.currentframe()).filename
mod_path = os.path.dirname(os.path.abspath(filename))
uic.loadUi(os.path.join(mod_path, "ui_files/FirstUser.ui"), self)

# Python >= 3.4

import pathlib
from PyQt5.QtWidgets import QMainWindow,QApplication
from PyQt5 import QtCore
from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = pathlib.Path(__file__).parent
        uic.loadUi(mod_path / "ui_files/FirstUser.ui", self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

# Python < 3.4

import os
from PyQt5.QtWidgets import QMainWindow,QApplication
from PyQt5 import QtCore
from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = os.path.dirname(__file__)
        uic.loadUi(os.path.join(mod_path, "ui_files/FirstUser.ui"), self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

# Python >= 3.4

import inspect
import pathlib

filename = inspect.getframeinfo(inspect.currentframe()).filename
mod_path = pathlib.Path(filename).resolve().parent
uic.loadUi(mod_path / "ui_files/FirstUser.ui", self)

# Python < 3.4

import inspect
import os

filename = inspect.getframeinfo(inspect.currentframe()).filename
mod_path = os.path.dirname(os.path.abspath(filename))
uic.loadUi(os.path.join(mod_path, "ui_files/FirstUser.ui"), self)
cuerpo editado
Origen Enlace
FJSevilla
  • 62.1k
  • 7
  • 43
  • 68

##### Python < 3.4 import osinspect import pathlibos

##### Python < 3.4 import os import pathlib

##### Python < 3.4 import inspect import os

se añadieron 226 caracteres en el cuerpo
Origen Enlace
FJSevilla
  • 62.1k
  • 7
  • 43
  • 68

##### Python >= 3.4 import pathlib from PyQt5.QtWidgets import QMainWindow,QApplication from PyQt5 import QtCore from PyQt5 import uic

import pathlib
from PyQt5.QtWidgets import QMainWindow,QApplication
from PyQt5 import QtCore
from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = pathlib.Path(__file__).parent
        uic.loadUi(mod_path / "ui_files/FirstUser.ui", self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

Si usas Python < 3.4 puedes usar os.path en vez de pathlib:

##### Python < 3.4 import os from PyQt5.QtWidgets import QMainWindow,QApplication from PyQt5 import QtCore from PyQt5 import uic

import os
from PyQt5.QtWidgets import QMainWindow,QApplication
from PyQt5 import QtCore
from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = os.path.dirname(__file__)
        uic.loadUi(os.path.join(mod_path, "ui_files/FirstUser.ui"), self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

Hay casos en los que __file__ no está definido o no puede ser usado como en módulos que dependen de librerías dinámicas en C, en intérpretes interactivos, etc. Otra posibilidad es usar el módulo inspect de la biblioteca estándar:

##### Python >= 3.4 import inspect import pathlib

filename = inspect.getframeinfo(inspect.currentframe()).filename
mod_path = pathlib.Path(filename).resolve().parent
uic.loadUi(mod_path / "ui_files/FirstUser.ui", self)

##### Python < 3.4 import os import pathlib

filename = inspect.getframeinfo(inspect.currentframe()).filename
mod_path = os.path.dirname(os.path.abspath(filename))
uic.loadUi(os.path.join(mod_path, "ui_files/FirstUser.ui"), self)
import pathlib
from PyQt5.QtWidgets import QMainWindow,QApplication
from PyQt5 import QtCore
from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = pathlib.Path(__file__).parent
        uic.loadUi(mod_path / "ui_files/FirstUser.ui", self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

Si usas Python < 3.4 puedes usar os.path en vez de pathlib:

import os
from PyQt5.QtWidgets import QMainWindow,QApplication
from PyQt5 import QtCore
from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = os.path.dirname(__file__)
        uic.loadUi(os.path.join(mod_path, "ui_files/FirstUser.ui"), self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

##### Python >= 3.4 import pathlib from PyQt5.QtWidgets import QMainWindow,QApplication from PyQt5 import QtCore from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = pathlib.Path(__file__).parent
        uic.loadUi(mod_path / "ui_files/FirstUser.ui", self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

Si usas Python < 3.4 puedes usar os.path en vez de pathlib:

##### Python < 3.4 import os from PyQt5.QtWidgets import QMainWindow,QApplication from PyQt5 import QtCore from PyQt5 import uic

class FirstUserClass(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        mod_path = os.path.dirname(__file__)
        uic.loadUi(os.path.join(mod_path, "ui_files/FirstUser.ui"), self)

        #Prpiedades de la Ventana
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)


if __name__ == "__main__":
    app = QApplication([])
    fcu = FirstUserClass()
    fcu.show()
    app.exec_()

Hay casos en los que __file__ no está definido o no puede ser usado como en módulos que dependen de librerías dinámicas en C, en intérpretes interactivos, etc. Otra posibilidad es usar el módulo inspect de la biblioteca estándar:

##### Python >= 3.4 import inspect import pathlib

filename = inspect.getframeinfo(inspect.currentframe()).filename
mod_path = pathlib.Path(filename).resolve().parent
uic.loadUi(mod_path / "ui_files/FirstUser.ui", self)

##### Python < 3.4 import os import pathlib

filename = inspect.getframeinfo(inspect.currentframe()).filename
mod_path = os.path.dirname(os.path.abspath(filename))
uic.loadUi(os.path.join(mod_path, "ui_files/FirstUser.ui"), self)
se añadieron 243 caracteres en el cuerpo
Origen Enlace
FJSevilla
  • 62.1k
  • 7
  • 43
  • 68
Loading
se añadieron 574 caracteres en el cuerpo
Origen Enlace
FJSevilla
  • 62.1k
  • 7
  • 43
  • 68
Loading
Origen Enlace
FJSevilla
  • 62.1k
  • 7
  • 43
  • 68
Loading