创建2个程序
- tool.py
- toolPy.bat
将编辑好的qt文件(.ui)放在该文件目录下,点击toolPy.bat文件后会生成对应的.py文件。如果再次使用会被覆盖原有文件。
1. tool.py
import os
import os.path
dir = './'
def listUiFile():
list = []
files = os.listdir(dir)
for filename in files:
#print( dir + os.sep + f )
#print(filename)
if os.path.splitext(filename)[1] == '.ui':
list.append(filename)
return list
def transPyFile(filename):
return os.path.splitext(filename)[0] + '.py'
def runMain():
list = listUiFile()
for uifile in list :
pyfile = transPyFile(uifile)
cmd = 'pyuic5 -o {pyfile} {uifile}'.format(pyfile=pyfile,uifile=uifile)
#print(cmd)
os.system(cmd)
if __name__ == "__main__":
runMain()
2. toolPy.bat
@echo off
CALL D:\Anaconda3\Scripts\activate.bat D:\Anaconda3
python tool.py
echo Completed: *.ui is transferred to *.py
echo end
pause