Fenêtre blanche en passant par un import module
Bonjour,
J'ai refai en miniature le test car je n'arrive pas à trouver d’où viens mon erreur...:calim2:
Quand j’exécute mon fichier python j'ai bien ma fenêtre mais toute blanche ?
J'ai créé l'interface via Designer (PyQt4) puis je l'importe dans second fichier python (fonctions.py).
Ce qui me donne dans mon dossier courant :
Code:
1 2 3
| __init__.py
fonctions.py
gui.py |
Dans mon fichier gui.py:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Class001.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(162, 59)
Form.setWindowTitle(_fromUtf8("Form"))
self.verticalLayout = QtGui.QVBoxLayout(Form)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.widget = QtGui.QWidget(Form)
self.widget.setObjectName(_fromUtf8("widget"))
self.gridLayout = QtGui.QGridLayout(self.widget)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.btn_A = QtGui.QPushButton(self.widget)
self.btn_A.setText(_fromUtf8("btn_A"))
self.btn_A.setObjectName(_fromUtf8("btn_A"))
self.gridLayout.addWidget(self.btn_A, 0, 0, 1, 1)
self.lbl_Btn_A = QtGui.QLabel(self.widget)
self.lbl_Btn_A.setObjectName(_fromUtf8("lbl_Btn_A"))
self.gridLayout.addWidget(self.lbl_Btn_A, 0, 1, 1, 1)
self.verticalLayout.addWidget(self.widget)
self.lbl_Btn_A.setBuddy(self.btn_A)
self.retranslateUi(Form)
QtCore.QObject.connect(self.btn_A, QtCore.SIGNAL(_fromUtf8("pressed()")), self.lbl_Btn_A.clear)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
self.lbl_Btn_A.setText(_translate("Form", "lbl_Btn_A", None)) |
Dans le fichier fonction.py :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
import sys
import os
from PyQt4 import QtGui
from gui import Ui_Form
class testCmd(QtGui.QMainWindow, Ui_Form):
def __init__(self):
QtGui.QMainWindow.__init__(self)
Ui_Form.__init__(self)
self.setupUi(self)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = testCmd()
window.show()
sys.exit(app.exec_()) |
info :
J'utilise l'IDE par défaut dans windows, l'ors de l’exécution (F5) de "fonction.py" il me créé un "gui.pyc".