# -*- coding: iso-8859-1 -*- #. // _qt_MainWindow.py #. // Crée une fenêtre principale. from os.path import isfile from PySide6.QtWidgets import QMainWindow from PySide6.QtGui import QIcon def qt_MainWindow( aOptions = [] ): #. // Valeurs par défaut. height = 300 # // Hauteur en pixels. width = 800 # // Largeur en pixels. top = 100 # // Position haute en pixels. left = 200 # // Position gauche en pixels. title = "Fenêtre QT" # // Titre. icon = "D:\\$Tools\\Icone\\Bernard.ico" # // Icône, testés : ico, bmp. mousetracking = True sizable = True # // Pour modifier la taille. #. // Prise des options. if len( aOptions ) > 0: for i in range( 0, len( aOptions ), 2 ): if aOptions[ i ] == "height": height = aOptions[ i + 1 ] elif aOptions[ i ] == "width": width = aOptions[ i + 1 ] elif aOptions[ i ] == "top": top = aOptions[ i + 1 ] elif aOptions[ i ] == "left": left = aOptions[ i + 1 ] elif aOptions[ i ] == "title": title = aOptions[ i + 1 ] elif aOptions[ i ] == "icon": icon = aOptions[ i + 1 ] elif aOptions[ i ] == "mousetracking": mousetracking = aOptions[ i + 1 ] elif aOptions[ i ] == "sizable": sizable = aOptions[ i + 1 ] #. endif #. endfor i #. endif oMain = QMainWindow() oMain.setMouseTracking( mousetracking ) oMain.setWindowTitle( title ) if isfile( icon ): oMain.setWindowIcon( QIcon( icon ) ) #. endif oMain.move( left, top ) if sizable: oMain.resize( width, height ) else: oMain.setFixedSize( width, height ) #. endif return oMain ''' Dernière modification : 2022-02-16 Pour lancer ce programme sans la console, utiliser << pythonw.exe Test.py >> https://doc.qt.io/qtforpython/PySide6/QtGui/QIcon.html https://doc.qt.io/qtforpython/PySide6/QtWidgets/QMainWindow.html [Todo] : Chercher d'autres options. [Exemple] import sys sys.path.append( "modules" ) from _qt_MainWindow import qt_MainWindow # // Crée une fenêtre principale. from os.path import dirname # // Extraire le dossier d'un fichier. from _by_CreateShortcut import by_CreateShortcut # // Crée un raccourci pour un lancer programme. from _by_dirbase import by_dirbase # // Renvoie le dossier par défaut avec ou sans << \ >> à la fin. from _by_msgbox import by_msgbox # // Boîte de dialogue avec options et valeur de retour. from _by_msgbox import MB_ICONINFORMATION # // Une icône composée d'une lettre minuscule i dans un cercle bleu apparaît dans la boîte de message. from _by_right import by_right # // Renvoie la partie droite demandée dans la chaîne. from _qt_init import qt_init # // Renvoie l'objet QT pour paramètres, exécutions et infos. from _qt_release import qt_release # // Ferme QT. #. // Création d'un raccourci pour lancer le programme sans la console. #. // sys.executable = Dossier et exe de Python. #. // sys.argv[ 0 ] = Nom du script en cours d'exécution sans son dossier. if not by_right( sys.executable, 5 ) == "w.exe": by_CreateShortcut( by_dirbase() + "_Lance" , dirname( sys.executable ) + "\\pythonw.exe" , by_dirbase( False) , sys.argv[ 0 ] , "D:\\$Tools\\Icone\\Roxanne.ico" ) by_msgbox( "Un raccourci a été créé", "qt_MainWindow()", MB_ICONINFORMATION ) app = qt_init() oMain = qt_MainWindow( [ "height" , 300 , "width" , 500 , "top" , 200 , "left" , 500 , "sizable" , False , "title" , "Test qt_MainWindow()" , "icon" , "D:\\$Tools\\Icone\\Warning.bmp" ] ) oMain.show() qt_release( app ) [/Exemple] '''