0

I am little confused by using the .ui file and .py file. I created a simple application using the pyqt designer and I used

UI_File, _ = loadUiType(path.join(path.dirname(__file__), 'dct-pages.ui'))

but I read other topic where we have to convert the ui file to py and import the py file into our codes, however my code is very simple and working without doing that

my question is do I need first to create the ui file and then generate the py file out of it then code what will be the situation if I wanted to change something in the UI, do I need everytime to regenerate the py file and import it

appreciate any pointers

1 Answer 1

1

You can either use the .ui file dynamically like you are already doing, or alternatively convert it to Python code using the pyuic5 utility (and yes, you have to regenerate the Python file every time use change the ui file in that case which is why I prefer to directly load the ui file as you have already done).

See the documentation for more details.

Sign up to request clarification or add additional context in comments.

2 Comments

what are the disadvantages for using the UI dynamically, there are some parameters I can not set. like for example setEchoMode() of a line edit when using a dynamic UI file. I could find an option to configure this for example
@Moo I'm not sure what you mean. If that option isn't available in Qt designer then it wouldn't be there in either the Python version or the dynamic version. You can of course configure that at runtime in both scenarios. For example, when loading dynamically you get back an object which holds a reference to each of the widgets, that you can then use as you please. Anything that can be done with the static Python file can also be done with the dynamic loading of the ui file. Could be worth asking a new question with a more detailed example if you find something you think only works in one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.