码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-03-12 14:23:28      阅读:62      评论:0      收藏:0      [点我收藏+]

标签:class   版本   文件   split   import   需要   pyqt5   错误   pre   

 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 = rd:\桌面\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) +  个文件)

 

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

标签:class   版本   文件   split   import   需要   pyqt5   错误   pre   

原文地址:https://www.cnblogs.com/xenli/p/12468780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!