Ui package pyuic5 conversion script file

Summary:

When using qtdesigner, if you need to convert files to save .ui .py file, you need to use the command line to convert

pyuic5 -o first.py firest.ui

Given each interface is open cmd trouble, the above operation can be encapsulated into a script that can be run directly

 

Code:

tools.py

Import OS
 Import the os.path 

# ui file path where 
the dir = ' ./ ' 

# list all the files in the directory ui 
DEF listUiFile (): 
    List = [] 
    Files = the os.listdir (the dir)
     for filename in Files:
         IF OS .path.splitext (filename) [. 1] == ' .ui ' : 
            list.append (filename) 
    return List 

# the file with the extension changed to .ui .py extension file 
DEF transPyFile (filename):
     return os.path.splitext (filename) [0] + '.py ' 

# call system command to convert the file into a python ui file 
DEF runMain (): 
    List = listUiFile ()
     for uifile in List: 
        pyfile = transPyFile (uifile) 
        cmd = ' pyuic5 pyfile -o {} {} uifile ' .format (pyfile = pyfile, uifile = uifile) Note # {pyfile}} uifile space between { 
     the os.system (cmd)

if __name__ == "__main__" :
  runMain()

The need to convert the file in the directory ui files, can be run directly

 

Guess you like

Origin www.cnblogs.com/reseelei-despair/p/11527729.html