pyqt5图形界面开发.ui转.py
放在ui文件存放的目录下,复制下面代码,运行即可。
import os
import os.path
# UI 文件所在路径
cwd = os.getcwd()
dir = os.path.join(cwd, "ui")
print(dir)
# 列出目录下的所有UI文件
def listUiFile():
list = []
files = os.listdir(dir)
print(files)
for filename in files:
if os.path.splitext(filename)[1] == '.ui':
list.append(os.path.join(dir, filename))
return list
# 把扩展名为.ui的文件改成扩展名为.py的文件
def transPyFile(filename):
return os.path.splitext(os.path.join(dir, filename))[0] + '.py'
# 调用系统命令把UI文件转成Python文件
def runMain():
list = listUiFile()
for uifile in list:
print(uifile)
pyfile = transPyFile(uifile)
print(pyfile)
cmd = 'pyuic5 -o {pyfile} {uifile}'.format(pyfile=pyfile, uifile=uifile)
os.system(cmd)
if __name__ == "__main__":
runMain()