0

我想创建一个简短的脚本,循环遍历文件夹中的所有 .ui 和 .qrc 文件,并为每个文件分别调用 pyuic4 和 pyrcc4 ,从而生成相应的 .py 文件。

几个月后在我了解更多python后编辑:

import shutil
import os


# pyrcc5 pixels.qrc -o pixels_rc.py && pyuic5 mainWindowGUI.ui -o MainWindowGUI.py && pyuic5 titleBarGUI.ui -o TitleBarGUI.py

command = 'pyrcc5 pixels.qrc -o pixels_rc.py'

for file in os.listdir(os.getcwd()):
    if file.endswith('ui'):
        filename = file.split('.')[0]
        command = f'{command} && pyuic5 {filename}.ui -o {filename}.py'

print(f'\n Executing: {command} \n')

try:
    result = os.system(command)
    if result is 0:
        pass
except Exception as e:
    print('Error {e}')

print('\n Done.')
4

1 回答 1

0
from pathlib import Path
import os

# generate something like this and the run it
# @echo off
# pyrcc5 pixels.qrc -o pixels_rc.py && pyuic5 window.ui -o window.py && pyuic5 dialog.ui -o dialog.py

command = f'pyrcc.exe Design/pixels.qrc -o GeneratedFiles/pixels_rc.py'

for file in os.listdir(Path(os.getcwd()+'/Design')):
    if file.endswith('ui'):
        filename = file.split('.')[0]
        command = command + f" && pyrcc.exe Design/{filename}.ui -o GeneratedFiles/{filename}.py"

try:
    result = os.system(command)
    if result == 0:
        pass
except Exception as e:
    print('Error {e}')

print('\n Done.')
于 2021-10-01T13:42:17.997 回答