Partage
  • Partager sur Facebook
  • Partager sur Twitter

comment afficher/masquer des frames dans PyQt5

afficher/masquer QFrame de PyQt5

    17 juillet 2019 à 8:29:04

    bonjour;

    j'essaye de créer pour test une fenêtre MainWindow que j'ai subdivise en deux blocs (bloc_right et bloc_left):

    bloc_left est un widgte QFrame vertical qui contient deux boutons QPushbutton : bouton1  et bouton2

    bloc_left est un widget QFrame qui doit normalement contenir deux widgtes QFrame "frame1"  et " frame2"

    je souhaite que lorque :

    * je clique sur le bouton , c'est la frame1 qui s'affiche avec son contenu.

    * si je clique sur le bouton2, la frame1 disparait et c'est la fram2 qui s’affiche avec son contenu

    j'ai utiliser deux fichiers (index.py) et ( main.ui)

    index.py :

    # PyQT5 :
    from PyQt5.QtWidgets import *
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.uic import loadUiType
    
    # import os :
    import os
    from os import path
    import sys
    
    # import UI_File :
    FORM_CLASS,_ = loadUiType(path.join(path.dirname(__file__),"main.ui"))
    
    #Initiate UI_File :
    class MainApp(QMainWindow,FORM_CLASS) :
        def __init__(self,parent=None) :
            super(MainApp,self).__init__(parent)
            QMainWindow.__init__(self)
            self.setupUi(self)
            self.mainUi()
            self.pushButton.clicked.connect(self.bouton1)
            self.pushButton_2.clicked.connect(self.bouton2)
        
        def mainUi(self):
            self.setWindowTitle("window for test")
    
        def bouton1(self)   :
            # hide the frame and its contents
            self.frame_3.hide()
            # show the frame and its contents
            self.frame_4.show() 
    
        def bouton2(self)   :
            # hide the frame and its contents
            self.frame_4.hide()
            # show the frame and its contents
            self.frame_3.show() 
    
    def main():
        app=QApplication(sys.argv)
        window=MainApp()
        window.show()
        app.exec_()# infinite loop
    
    if __name__=='__main__' :
        main()
    



    main.ui :(cree avec Qtdesigner)

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>MainWindow</class>
     <widget class="QMainWindow" name="MainWindow">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>640</width>
        <height>460</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>MainWindow</string>
      </property>
      <widget class="QWidget" name="centralwidget">
       <widget class="QFrame" name="frame">
        <property name="geometry">
         <rect>
          <x>1</x>
          <y>0</y>
          <width>120</width>
          <height>460</height>
         </rect>
        </property>
        <property name="styleSheet">
         <string notr="true">background-color: rgb(182, 182, 182);</string>
        </property>
        <property name="frameShape">
         <enum>QFrame::StyledPanel</enum>
        </property>
        <property name="frameShadow">
         <enum>QFrame::Raised</enum>
        </property>
        <widget class="QPushButton" name="pushButton">
         <property name="geometry">
          <rect>
           <x>20</x>
           <y>70</y>
           <width>75</width>
           <height>23</height>
          </rect>
         </property>
         <property name="text">
          <string>bouton1</string>
         </property>
        </widget>
        <widget class="QPushButton" name="pushButton_2">
         <property name="geometry">
          <rect>
           <x>20</x>
           <y>300</y>
           <width>75</width>
           <height>23</height>
          </rect>
         </property>
         <property name="text">
          <string>bouton2</string>
         </property>
        </widget>
       </widget>
       <widget class="QFrame" name="frame_2">
        <property name="geometry">
         <rect>
          <x>119</x>
          <y>0</y>
          <width>520</width>
          <height>460</height>
         </rect>
        </property>
        <property name="styleSheet">
         <string notr="true">background-color: rgb(0, 0, 0);</string>
        </property>
        <property name="frameShape">
         <enum>QFrame::StyledPanel</enum>
        </property>
        <property name="frameShadow">
         <enum>QFrame::Raised</enum>
        </property>
        <widget class="QFrame" name="frame_3">
         <property name="geometry">
          <rect>
           <x>0</x>
           <y>0</y>
           <width>520</width>
           <height>460</height>
          </rect>
         </property>
         <property name="styleSheet">
          <string notr="true">background-color: rgb(170, 255, 255);</string>
         </property>
         <property name="frameShape">
          <enum>QFrame::StyledPanel</enum>
         </property>
         <property name="frameShadow">
          <enum>QFrame::Raised</enum>
         </property>
         <widget class="QFrame" name="frame_4">
          <property name="geometry">
           <rect>
            <x>0</x>
            <y>0</y>
            <width>520</width>
            <height>460</height>
           </rect>
          </property>
          <property name="styleSheet">
           <string notr="true">background-color: rgb(255, 255, 127);</string>
          </property>
          <property name="frameShape">
           <enum>QFrame::StyledPanel</enum>
          </property>
          <property name="frameShadow">
           <enum>QFrame::Raised</enum>
          </property>
         </widget>
        </widget>
       </widget>
      </widget>
      <widget class="QMenuBar" name="menubar">
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>0</y>
         <width>640</width>
         <height>23</height>
        </rect>
       </property>
       <widget class="QMenu" name="menuILS">
        <property name="title">
         <string>ILS</string>
        </property>
        <addaction name="actionILS_35R"/>
        <addaction name="actionILS_35L"/>
       </widget>
       <widget class="QMenu" name="menuInfo">
        <property name="title">
         <string>Info</string>
        </property>
        <addaction name="actionA_propos_de_l_application"/>
       </widget>
       <addaction name="menuILS"/>
       <addaction name="menuInfo"/>
      </widget>
      <action name="actionILS_35R">
       <property name="text">
        <string>ILS 35R</string>
       </property>
      </action>
      <action name="actionILS_35L">
       <property name="text">
        <string>ILS 35L</string>
       </property>
      </action>
      <action name="actionA_propos_de_l_application">
       <property name="text">
        <string>A propos de l'application</string>
       </property>
      </action>
     </widget>
     <resources/>
     <connections/>
    </ui>
    

    y a t'il de proposition pour me guider a realiser ceci Merci

    • Partager sur Facebook
    • Partager sur Twitter

    comment afficher/masquer des frames dans PyQt5

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown