PyQt5UI文件转换为对应版本的py文件

 PyQt5 UI文件转换为对应版本的py文件

 1 #coding=utf-8
 2 '''
 3 PyQt5 UI文件转换为对应版本的py文件
 4 python -m PyQt5.uic.pyuic untitled.ui -o untitled.py
 5 '''
 6 import os
 7 
 8 # 此处的path为UI文件存放的路径
 9 path = r'd:\桌面\Tickets'
10 
11 # 记录转换成功的文件数量
12 count = 0
13 for root, dirs, files in os.walk(path):
14     filename = []
15     for file in files:
16         if file.endswith('.py'):
17             filename2 = file.split('.')[0]
18             filename.append(filename2)
19   
20     for file in files:
21         if file.endswith('.ui'):
22             filename1 = file.split('.')[0]
23             filename5 = filename1 + "_qt5"
24             try:
25                 if filename.count(filename5) == 0:
26                     os.system('python -m PyQt5.uic.pyuic -o %s.py %s.ui -d' % (path + '\\' + filename5, path + '\\' + filename1))
27                     count += 1
28             except Exception as e:
29                 print("文件转化错误,请检查是否正确安装指令对应PyQt")
30                 raise e
31 if count == 0:
32     print("暂无需要转换的UI文件")
33 else:
34     print('转换完毕,请查收!本次共转换 ' + str(count) + ' 个文件')

猜你喜欢

转载自www.cnblogs.com/xenli/p/12468780.html