Skip to content

Instantly share code, notes, and snippets.

@B0und
Last active August 25, 2020 20:41
Show Gist options
  • Save B0und/e697089cbf9ca3596e98ba9014f4949a to your computer and use it in GitHub Desktop.
Save B0und/e697089cbf9ca3596e98ba9014f4949a to your computer and use it in GitHub Desktop.
Automatically convert qt designer .ui and .qrc files to .py
"""
Recursively looks through files and converts .ui and .qrc qt designer files to python code.
Just import this file at the top of your main module.(Dont forget to comment out before deploying)
"""
import os
from pathlib import Path
# convert interface
for path in Path('').rglob('*.ui'):
path_folder = path.parents[0]
path_filename = path.stem
res_path = Path(path_folder, path_filename + "_ui.py")
os.system(f"python -m PyQt5.uic.pyuic -x {path} -o {res_path}")
# convert icons
for path in Path('').rglob('*.qrc'):
path_folder = path.parents[0]
path_filename = path.stem
res_path = Path(path_folder, path_filename + "_rc.py")
os.system(f"python -m PyQt5.pyrcc_main {path} -o {res_path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment