Bienvenue sur Induste !

En vous inscrivant, vous pourrez discuter, partager et envoyer des messages privés avec d'autres membres de notre communauté.

Je m'inscris !

Question << HELP >> python Qt

AOM-Alpha

ProGameur , Decerto
Premium
Inscription
19 Juin 2015
Messages
331
Réactions
41
Points
9 556
    Réponse de AOM-Alpha Informatique et nouvelles technologies Développement Questions, aides et recherches : << HELP >> python Qt
  • #1
Alors voilà j’ai créer une application de gestion de mot de passe.
Probleme, elle est en ligne de commande, ce qui n’est pas du plus joli.
J’ai donc découvert Qt creator qui permet de faire des fenêtre graphique assez simple.
Mon code marche correctement mais il me reste un seul soucis à régler, je m’explique :
Pour passer d’une fenêtre à une autre j’ai suivi cette vidéo :
Vous devez être inscrit pour voir les médias
Après avoir suivi le tuto cela fonctionne correctement. Sauf que lorsque je veux refaire la même chose à partir de la deuxièmes fenêtre( donc quand je veux ouvrir une troisième fenêtre), elle s’ouvre correctement mais pas moyen de fermer la deuxième, j’ai à peut près tout essayer et là je sèche.
es ce que quelqu’un pourrait me venir en aide ?
la partie qui envoie sur l'autre fenetre est le code : gsc()
de la deuxieme a la troisieme c'est le code : go()
########
voila le code que j'excecute :
Python:
class Ui_Main(object):
    def __init__(self):
        super().__init__()
        self.go_to_gsc = False
    def majtext(self):
        dispo = MAJ.run()
        if dispo == None:
            self.maj.setEnabled(False)
            self.version_check.setPixmap(QtGui.QPixmap("../../Pictures/d9jcs7k-2a4c1cab-da0e-40a4-8bf2-246ebe2e9fa4.png"))
        if dispo == True:
            self.version_check_4.setText("OFF")
            self.version_check_4.setStyleSheet("color: rgb(170, 0, 0)")
    def usertext(self):
        liste = []
        with open('ID.txt') as file:
            for line in file :
                liste += [line.strip()]
        user = liste[2]
        self.version_check_3.setText(user)
    def versiontext(self):
        with open('version.txt') as file:
            for line in file :
                v = line.strip()
        self.version_check_2.setText(v)
    def gsc(self):
        self.window = QtWidgets.QDialog()
        self.ui = Ui_Connexion()
        self.ui.setupUi(self.window)
        Main.hide()
        self.window.show()
       
    def url(self):
        self.window = QtWidgets.QDialog()
        self.ui = Ui_URLSC()
        self.ui.setupUi(self.window)
        Main.hide()
        self.window.show()
    def local(self):
        self.window = QtWidgets.QDialog()
        self.ui = Ui_LOCALSC()
        self.ui.setupUi(self.window)
        Main.hide()
        self.window.show()
    def MAJ(self):
        self.window = QtWidgets.QDialog()
        self.ui = Ui_MAJSC()
        self.ui.setupUi(self.window)
        Main.hide()
        self.window.show()
    def setupUi(self, Main):
        Main.setObjectName("Main")
        Main.resize(812, 600)
        Main.setMinimumSize(QtCore.QSize(456, 360))
        Main.setMaximumSize(QtCore.QSize(1000, 1000))
        font = QtGui.QFont()
        font.setFamily("Gumbo DEMO")
        font.setPointSize(16)
        font.setItalic(False)
        Main.setFont(font)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("../Pictures/ghost-writer-2183856_960_720.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        Main.setWindowIcon(icon)
        Main.setStyleSheet("background-color: rgb(111, 111, 111);")
        Main.setSizeGripEnabled(False)
        self.name = QtWidgets.QLabel(Main)
        self.name.setGeometry(QtCore.QRect(200, 40, 491, 61))
        font = QtGui.QFont()
        font.setFamily("Gumbo DEMO")
        font.setPointSize(36)
        font.setItalic(False)
        self.name.setFont(font)
        self.name.setStyleSheet("color: rgb(116, 206, 191);")
        self.name.setObjectName("name")
        self.Gestionnaire = QtWidgets.QPushButton(Main)
        self.Gestionnaire.setGeometry(QtCore.QRect(30, 160, 161, 161))
        self.Gestionnaire.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.Gestionnaire.setAutoFillBackground(False)
        self.Gestionnaire.setStyleSheet("color : rgb(255, 255, 255);\n"
"alternate-background-color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 255, 255);")
        self.Gestionnaire.setText("")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("../../Pictures/cyber.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.Gestionnaire.setIcon(icon1)
        self.Gestionnaire.setIconSize(QtCore.QSize(200, 200))
        self.Gestionnaire.setFlat(False)
        self.Gestionnaire.setObjectName("Gestionnaire")
        self.URL = QtWidgets.QPushButton(Main)
        self.URL.setGeometry(QtCore.QRect(220, 160, 171, 161))
        self.URL.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.URL.setStyleSheet("color : rgb(255, 255, 255);\n"
"alternate-background-color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 255, 255);")
        self.URL.setText("")
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("../../Pictures/1931235.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.URL.setIcon(icon2)
        self.URL.setIconSize(QtCore.QSize(162, 180))
        self.URL.setObjectName("URL")
        self.appli = QtWidgets.QPushButton(Main)
        self.appli.setGeometry(QtCore.QRect(420, 160, 171, 161))
        self.appli.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.appli.setStyleSheet("color : rgb(255, 255, 255);\n"
"alternate-background-color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 255, 255);")
        self.appli.setText("")
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap("../../Pictures/logo_redirect_512.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.appli.setIcon(icon3)
        self.appli.setIconSize(QtCore.QSize(145, 180))
        self.appli.setObjectName("appli")
        self.maj = QtWidgets.QPushButton(Main)
        self.maj.setGeometry(QtCore.QRect(620, 160, 161, 161))
        self.maj.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.maj.setStyleSheet("color : rgb(255, 255, 255);\n"
"alternate-background-color: rgb(255, 255, 255);\n"
"background-color: rgb(255, 255, 255);")
        self.maj.setText("")
        icon4 = QtGui.QIcon()
        icon4.addPixmap(QtGui.QPixmap("../../Pictures/mise-a-jour.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.maj.setIcon(icon4)
        self.maj.setIconSize(QtCore.QSize(145, 180))
        self.maj.setObjectName("maj")
        self.label = QtWidgets.QLabel(Main)
        self.label.setGeometry(QtCore.QRect(10, 10, 141, 121))
        self.label.setText("")
        self.label.setTextFormat(QtCore.Qt.AutoText)
        self.label.setPixmap(QtGui.QPixmap("../papi/ghost.ico"))
        self.label.setScaledContents(True)
        self.label.setObjectName("label")
        self.name_2 = QtWidgets.QLabel(Main)
        self.name_2.setGeometry(QtCore.QRect(50, 320, 131, 21))
        font = QtGui.QFont()
        font.setFamily("Gumbo DEMO")
        font.setPointSize(14)
        font.setItalic(False)
        self.name_2.setFont(font)
        self.name_2.setStyleSheet("color : rgb(255, 178, 172);")
        self.name_2.setObjectName("name_2")
        self.name_3 = QtWidgets.QLabel(Main)
        self.name_3.setGeometry(QtCore.QRect(280, 320, 41, 31))
        font = QtGui.QFont()
        font.setFamily("Gumbo DEMO")
        font.setPointSize(14)
        font.setItalic(False)
        self.name_3.setFont(font)
        self.name_3.setStyleSheet("color: rgb(0, 0, 0);")
        self.name_3.setObjectName("name_3")
        self.name_4 = QtWidgets.QLabel(Main)
        self.name_4.setGeometry(QtCore.QRect(480, 320, 51, 31))
        font = QtGui.QFont()
        font.setFamily("Gumbo DEMO")
        font.setPointSize(14)
        font.setItalic(False)
        self.name_4.setFont(font)
        self.name_4.setStyleSheet("color: rgb(255, 170, 0);")
        self.name_4.setObjectName("name_4")
        self.name_5 = QtWidgets.QLabel(Main)
        self.name_5.setGeometry(QtCore.QRect(640, 320, 131, 31))
        font = QtGui.QFont()
        font.setFamily("Gumbo DEMO")
        font.setPointSize(14)
        font.setItalic(False)
        self.name_5.setFont(font)
        self.name_5.setStyleSheet("color: rgb(213, 51, 51)")
        self.name_5.setObjectName("name_5")
        self.version = QtWidgets.QLabel(Main)
        self.version.setGeometry(QtCore.QRect(20, 380, 341, 201))
        font = QtGui.QFont()
        font.setFamily("Gumbo DEMO")
        font.setPointSize(20)
        font.setItalic(False)
        self.version.setFont(font)
        self.version.setStyleSheet("color: rgb(116, 206, 191);")
        self.version.setObjectName("version")
        self.version_check = QtWidgets.QLabel(Main)
        self.version_check.setGeometry(QtCore.QRect(130, 370, 51, 51))
        font = QtGui.QFont()
        font.setFamily("Gumbo DEMO")
        font.setPointSize(20)
        font.setItalic(False)
        self.version_check.setFont(font)
        self.version_check.setStyleSheet("color: rgb(111, 111, 111);")
        self.version_check.setText("")
        self.version_check.setPixmap(QtGui.QPixmap("../../Pictures/power-1762980_960_720.png"))
        self.version_check.setScaledContents(True)
        self.version_check.setObjectName("version_check")
        self.version_check_2 = QtWidgets.QLabel(Main)
        self.version_check_2.setGeometry(QtCore.QRect(160, 440, 641, 31))
        font = QtGui.QFont()
        font.setFamily("Gumbo DEMO")
        font.setPointSize(20)
        font.setItalic(False)
        self.version_check_2.setFont(font)
        self.version_check_2.setStyleSheet("color: rgb(0, 255, 127)")
        self.version_check_2.setScaledContents(False)
        self.version_check_2.setObjectName("version_check_2")
        self.version_check_3 = QtWidgets.QLabel(Main)
        self.version_check_3.setGeometry(QtCore.QRect(200, 490, 641, 41))
        font = QtGui.QFont()
        font.setFamily("Gumbo DEMO")
        font.setPointSize(20)
        font.setItalic(False)
        self.version_check_3.setFont(font)
        self.version_check_3.setStyleSheet("color: rgb(0, 255, 127)")
        self.version_check_3.setScaledContents(False)
        self.version_check_3.setObjectName("version_check_3")
        self.version_check_4 = QtWidgets.QLabel(Main)
        self.version_check_4.setGeometry(QtCore.QRect(140, 540, 141, 41))
        font = QtGui.QFont()
        font.setFamily("Gumbo DEMO")
        font.setPointSize(20)
        font.setItalic(False)
        self.version_check_4.setFont(font)
        self.version_check_4.setStyleSheet("color: rgb(0, 255, 127)")
        self.version_check_4.setScaledContents(False)
        self.version_check_4.setObjectName("version_check_4")
        ####click
        self.Gestionnaire.clicked.connect(self.gsc)
        self.URL.clicked.connect(self.url)
        self.appli.clicked.connect(self.local)
        self.maj.clicked.connect(self.MAJ)
        ###end
       

        self.retranslateUi(Main)
        QtCore.QMetaObject.connectSlotsByName(Main)

    def retranslateUi(self, Main):
        _translate = QtCore.QCoreApplication.translate
        Main.setWindowTitle(_translate("Main", "APi"))
        self.name.setText(_translate("Main", "Bienvenue sur APi"))
        self.name_2.setText(_translate("Main", "<html><head/><body><p>Gestionnaire</p></body></html>"))
        self.name_3.setText(_translate("Main", "<html><head/><body><p>URL</p></body></html>"))
        self.name_4.setText(_translate("Main", "Local"))
        self.name_5.setText(_translate("Main", "Mise à jour"))
        self.version.setText(_translate("Main", "<html><head/><body><p>Online : </p><p>Version : </p><p>Utilisateur : </p><p>À jour : </p></body></html>"))
        self.version_check_2.setText(_translate("Main", "2.0"))
        self.version_check_3.setText(_translate("Main", "User"))
        self.version_check_4.setText(_translate("Main", "ON"))
        ###fcnt
        self.versiontext()
        self.usertext()
        self.majtext()
        ###end


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Main = QtWidgets.QDialog()
    ui = Ui_Main()
    ui.setupUi(Main)
    Main.show()
    sys.exit(app.exec_())
voila la deuxieme fenetre :
Python:
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'CONECT.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets
from GSC import Ui_GSC
import security, sys, os, time

class Ui_Connexion(object):
    def __init__(self):
        super().__init__()
        self.life = 3
    def go(self):
        self.window = QtWidgets.QDialog()
        self.ui = Ui_GSC()
        self.ui.setupUi(self.window)
        self.window.show()
    def verify(self):
        mdp = self.lineEdit.text()
        if not security.verify(mdp):
            self.life -= 1
            self.label_5.setText("Mot de passe incorrecte, "+str(self.life)+" essais restants")
            if self.life == 0:
                sys.exit(app.exec_())
        else:
            self.label_5.setStyleSheet("color: rgb(0, 255, 127);")
            self.label_5.setText("Mot de passe correcte")
            self.go()
       
    def usertext(self):
        with open('ID.txt') as file:
            liste = []
            for line in file:
                liste += [line.strip()]
        user = liste[2]
        self.label_3.setText("USER: "+ user)
    def setupUi(self, Connexion):
        Connexion.setObjectName("Connexion")
        Connexion.resize(541, 442)
        Connexion.setStyleSheet("background-color: rgb(0, 170, 255)")
        self.label = QtWidgets.QLabel(Connexion)
        self.label.setGeometry(QtCore.QRect(180, 0, 211, 201))
        self.label.setText("")
        self.label.setPixmap(QtGui.QPixmap("../../Pictures/1070509.png"))
        self.label.setScaledContents(True)
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Connexion)
        self.label_2.setGeometry(QtCore.QRect(10, 280, 101, 91))
        font = QtGui.QFont()
        font.setFamily("Coconut Cookies")
        font.setPointSize(36)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(Connexion)
        self.label_3.setGeometry(QtCore.QRect(10, 210, 471, 61))
        font = QtGui.QFont()
        font.setFamily("Coconut Cookies")
        font.setPointSize(36)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.pushButton = QtWidgets.QPushButton(Connexion)
        self.pushButton.setGeometry(QtCore.QRect(170, 380, 191, 51))
        font = QtGui.QFont()
        font.setFamily("Coconut Cookies")
        font.setPointSize(20)
        self.pushButton.setFont(font)
        self.pushButton.setFlat(False)
        self.pushButton.setObjectName("pushButton")
        self.label_4 = QtWidgets.QLabel(Connexion)
        self.label_4.setGeometry(QtCore.QRect(0, 0, 81, 81))
        self.label_4.setText("")
        self.label_4.setPixmap(QtGui.QPixmap("../papi/cyber.ico"))
        self.label_4.setScaledContents(True)
        self.label_4.setObjectName("label_4")
        self.lineEdit = QtWidgets.QLineEdit(Connexion)
        self.lineEdit.setGeometry(QtCore.QRect(120, 310, 411, 41))
        font = QtGui.QFont()
        font.setFamily("Coconut Cookies")
        font.setPointSize(16)
        self.lineEdit.setFont(font)
        self.lineEdit.setText("")
        self.lineEdit.setEchoMode(QtWidgets.QLineEdit.Password)
        self.lineEdit.setObjectName("lineEdit")
        self.label_5 = QtWidgets.QLabel(Connexion)
        self.label_5.setGeometry(QtCore.QRect(90, 350, 501, 31))
        font = QtGui.QFont()
        font.setFamily("Coconut Cookies")
        font.setPointSize(14)
        self.label_5.setFont(font)
        self.label_5.setStyleSheet("color: rgb(170, 0, 0);")
        self.label_5.setObjectName("label_5")
        self.label_2.raise_()
        self.label_5.raise_()
        self.label.raise_()
        self.label_3.raise_()
        self.pushButton.raise_()
        self.label_4.raise_()
        self.lineEdit.raise_()

        self.retranslateUi(Connexion)
        self.usertext()
        self.pushButton.clicked.connect(self.verify)
        QtCore.QMetaObject.connectSlotsByName(Connexion)

    def retranslateUi(self, Connexion):
        _translate = QtCore.QCoreApplication.translate
        Connexion.setWindowTitle(_translate("Connexion", "Dialog"))
        self.label_2.setText(_translate("Connexion", "MDP: "))
        self.label_3.setText(_translate("Connexion", "USER: "))
        self.pushButton.setText(_translate("Connexion", "CHECK"))
        self.lineEdit.setPlaceholderText(_translate("Connexion", "Entrer le mot de passe ..."))
        self.label_5.setText(_translate("Connexion", ""))


def run():
    app2 = QtWidgets.QApplication(sys.argv)
    Connexion = QtWidgets.QDialog()
    ui2 = Ui_Connexion()
    ui2.setupUi(Connexion)
    Connexion.show()
    sys.exit(app.exec_())
la troisieme fenetre :
Python:
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'GSC.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_GSC(object):
    def setupUi(self, GSC):
        GSC.setObjectName("GSC")
        GSC.resize(951, 733)
        self.voir = QtWidgets.QGroupBox(GSC)
        self.voir.setGeometry(QtCore.QRect(10, 10, 311, 711))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.voir.setFont(font)
        self.voir.setObjectName("voir")
        self.listWidget = QtWidgets.QListWidget(self.voir)
        self.listWidget.setGeometry(QtCore.QRect(10, 50, 281, 521))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.listWidget.setFont(font)
        self.listWidget.setObjectName("listWidget")
        with open('user.txt') as file:
            listeuser = []
            for line in file:
                listeuser += [line.strip()]
        for c in listeuser:
            globals() [c] = QtWidgets.QListWidgetItem()
            exec("self.listWidget.addItem(" + c + ")")
            exec(c + ".setText('"+ c + "')")
        self.lineEdit = QtWidgets.QLineEdit(self.voir)
        self.lineEdit.setGeometry(QtCore.QRect(10, 590, 281, 31))
        font = QtGui.QFont()
        font.setPointSize(18)
        self.lineEdit.setFont(font)
        self.lineEdit.setEchoMode(QtWidgets.QLineEdit.Password)
        self.lineEdit.setObjectName("lineEdit")
        self.pushButton = QtWidgets.QPushButton(self.voir)
        self.pushButton.setGeometry(QtCore.QRect(40, 640, 201, 61))
        self.pushButton.setObjectName("pushButton")

        self.retranslateUi(GSC)
        QtCore.QMetaObject.connectSlotsByName(GSC)

    def retranslateUi(self, GSC):
        _translate = QtCore.QCoreApplication.translate
        GSC.setWindowTitle(_translate("GSC", "Dialog"))
        self.voir.setTitle(_translate("GSC", "Mots de passe"))
        __sortingEnabled = self.listWidget.isSortingEnabled()
        self.listWidget.setSortingEnabled(False)
        self.listWidget.setSortingEnabled(__sortingEnabled)
        self.lineEdit.setPlaceholderText(_translate("GSC", "Entrer le mot clef ..."))
        self.pushButton.setText(_translate("GSC", "Afficher"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    GSC = QtWidgets.QDialog()
    ui = Ui_GSC()
    ui.setupUi(GSC)
    GSC.show()
    sys.exit(app.exec_())
Ce qui pose problème c’est que le MAIN.hide() ne peut pas être utiliser dans la deuxièmes fonction car il n’existe pas mais du coup je en sais pas quoi faire
 
Dernière édition:

Haut Bas