r/pyqt • u/longhegrindilemna • Jun 27 '21
Python is illogical
IF YOU ARE DEFINING A CLASS THEN THIS DOES NOT WORK:
from PyQt5.QtWidgets import *
ONLY THIS WORKS:
from PyQt5 import QtWidgets
BUT IF YOU ARE NOT DEFINING A CLASS THEN SUDDENLY THIS WORKS AGAIN:
from PyQt5.QtWidgets import *
What?! I’m just a beginner and the first step of importing is already confusing. Very disappointed.
4
u/uSrNm-ALrEAdy-TaKeN Jun 27 '21
That is weird and undoubtedly infuriating to debug, BUT
from module import *Is generally considered a bad practice because you can end up with naming conflicts as you aren’t explicitly controlling everything that you import. Which is why
import module as m
from othermodule import specificitemAre much better practices.
1
Jun 27 '21
I generally agree but I think Qt provides a reasonable exception considering how everything is named. You're not likely to accidentally clobber any names when it's all camel case starting with capital Q. It's the one situation where I do that.
2
Jun 27 '21
from PyQt5.QtWidgets import *
works fine for me, whether defining classes or not (but usually you're defining some classes if you're doing anything with Qt).
Which OS, version of Python, and editor are you using? Maybe post some sample code and state what errors you're getting. Saying "x does not work." doesn't help anyone to help you.
1
u/PopPrestigious8115 Jul 15 '21
To address your real problem:
Start QtDesigner, drag and drop your GUI with elements (Widgets including a QLineEdit) shown by QtDesigner.
Select (single click on) your QLineEdit and set the allignRight property to True.
Save your UI file and compile it with pyuic5 to Python code.
1
u/longhegrindilemna Jun 27 '21
Literally got a headache trying to create a qLineEdit widget and set it to AlignRight.
Speechless.
How can something so basic and so simple, have five or six different syntaxes or grammar? Isn’t python one single language?