UI to PY but not window when run in python
-
Hi, total newbie here. I have just installed the designer and created a very simple window to test it all worked, just a button sitting in the middle. If I load the ui file and convert in python it works just fine (code below)
import sys from PyQt5 import QtWidgets, uic app = QtWidgets.QApplication(sys.argv) window = uic.loadUi("practice.ui") window.show() app.exec()
However, if I load the py file nothing happens when I run the file, I am guessing that the program is waiting for me to open the window, am I missing an obvious piece of code.
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'practice.ui' # # Created by: PyQt5 UI code generator 5.9.2 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Frame(object): def setupUi(self, Frame): Frame.setObjectName("Frame") Frame.resize(319, 395) self.verticalLayoutWidget = QtWidgets.QWidget(Frame) self.verticalLayoutWidget.setGeometry(QtCore.QRect(100, 0, 121, 461)) self.verticalLayoutWidget.setObjectName("verticalLayoutWidget") self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.pushButton = QtWidgets.QPushButton(self.verticalLayoutWidget) self.pushButton.setObjectName("pushButton") self.verticalLayout.addWidget(self.pushButton) self.retranslateUi(Frame) QtCore.QMetaObject.connectSlotsByName(Frame) def retranslateUi(self, Frame): _translate = QtCore.QCoreApplication.translate Frame.setWindowTitle(_translate("Frame", "Frame")) self.pushButton.setText(_translate("Frame", "PushButton"))
-
@AndyPaul said in UI to PY but not window when run in python:
adding the -x brought up the missing window :-)
If your issue is solved, please don't forget to mark your post as such.
-
@AndyPaul Why would anything happen if you just load the file? It contains a class definition and nothing more. You have to create a widget, the form object (
Ui_Frame
) and call theUi_Frame.setupUi
on the widget to get something shown. (@SGaist's link provides an example)@Denni-0 said in UI to PY but not window when run in python:
@AndyPaul be forewarned that dealing with the UI is just going to be one headache after another and I speak to you from experience as I have taught numerous students who were struggling with one problem or another with getting their normal Python-Qt code to work with the UI.
And I've had a long, long time working with Qt, and have taught numerous students in C++, not to mention physics. So what you claim, even if we go on a limb and believe to be true, is completely irrelevant here. Be forewarned you're neither the only one around knowing stuff, nor are you the leanest and meanest; not to mention that your opinions are by far not the chisel to the stone.
The were also quite surprised just how easy it was to create normal Python-Qt GUIs once they understood how.
Really. Have you ever considered that the designer generates just normal code. Code generation tools are there for a reason - to spare people tedious mind-numbing repetitive tasks that machines do better and faster. I know, just perplexing, right? Can you believe such craziness?
Further they found it was just as quick and quicker if you factor in all the time wasted on working with the UI after its made.
Sure, if you don't know what the heck you're doing; it'd have been your job to teach them if I understand it correctly. Not having the faintest clue of how an engine works is faulty reasoning to reinvent the Otto cycle.
So it is a lot better in the long run to learn Python-Qt GUI creation than it is to keep leaning on the horrible crutch that the Designer is as it only crippled you as a programmer and thus holds you back from gaining your true potentiality
Programming can't be reduced to putting a couple of controls to a user interface and being an obnoxious self-righteous punk ain't helping nobody reach any potential they may've had. So drop the platitudes, will ya? Just stick to the problem at hand.
-
@Denni-0 said in UI to PY but not window when run in python:
@AndyPaul be forewarned that dealing with the UI is just going to be one headache after another and I speak to you from experience as I have taught numerous students who were struggling with one problem or another with getting their normal Python-Qt code to work with the UI.
If there is a problem with the code generated from pyuic5 then please report this at https://bugreports.qt.io as bug reports are welcome and if something can be improved its best to report this accordingly. If you are just saying that it is easier to write a UI directly instead of using pyuic with a ui file, this may be true for some people. But it is available there as a tool for people to use, they may find it better for their needs to generate it using pyuic5 to save time or because they have no problem with using it.
So if there is an actual problem, report it, otherwise there is no reason to be critical of someone's choice. If a problem arises from actually using the tool, then of course it is fine to suggest doing it directly instead of using the tool to solve the problem.
-
@Denni-0 said in UI to PY but not window when run in python:
Well even after doing all this unnecessary stuff to make a UI work that is not needed when using Python-Qt the way it was meant to be used -- the UI still has functional issues AND most importantly it is untouchable black-box code which any experienced programmer worth their salt knows that introducing these kind of things (untouchable black-box code) into a program is always dangerous and needs to be avoided unless absolutely necessary and even then these untouchable black-box APIs are almost always a headache. Not always mind you but enough to have given using them a very bad reputation in the industry
None of this is even remotely close to true, nor is it any helpful, nor is your opinion worth any more than the next guy's. So I feel justified in classifying it in the "yet another useless platitude" folder. Thanks for playing!
And what does C++ have to do with Python
The same thing that your claim you've taught students has to do with the original question - absolutely nothing. That's why I inserted this illustration there, as yet another example of why what you write has practically no merit.
That being said I have numerous years of experience using/teaching C, C++, C#, VB.Net, and the list goes on.
Good for you. For me, *shrug*, I could care less, I only care about what you wrote, which has very little to do with the actual question. Which I'd be more than glad to remind you was:
However, if I load the py file nothing happens when I run the file, I am guessing that the program is waiting for me to open the window, am I missing an obvious piece of code.
So yeah I know what I am talking about and when I do not know I either find out the facts or I simply state I do not know -- I am not omnipotent nor do I pretend to be so
... except when you crusade to show that you are ...
-- further I teach all my students to think for themselves and that goes for anything I share with them as I do not want them to be lemmings like many other programmers out there seem to be.
Oh thanks, we lemmings, designer-lovers and akin really value your opinion on our miserable existence. Get a life, dude.
Analyze it, know it and then make your own decision.
I already have, I have used the designer for years. That's how I know what needs to be done to show the window when I don't know any python. Surprise, surprise, I do the same in C++.
As for others out there being knowledgeable sure and some of them are even students of mine and they teach me a thing or two from time to time. As a teacher I know that I am never going to be the source of all information nor do I want to be -- I am simply A source that encourages folks to do their own research your warning is totally meaningless and almost troll like in presentation
It wasn't a warning. I was paraphrasing your pretentious tone for sarcastic purposes.
(which I will be notifying moderators about).
Bite me. You know where you can find the admin, since he's already replied to this thread. If I warrant a ban for trolling, so be it, I take responsibility for what I say and do. I'm still going to say/do it, but I don't run from the consequences. As for how trolling it was, it seems to me that the local community disagrees with you. I've rarely seen people being downvoted, and even more so someone as downvoted as you. A piece of unsolicited advice: take note of that.
Yes I have and No it does not generate normal code in the sense of it being used within Python it generates XML Code
For which there's the user interface compiler to bring to python, just the same as for C++. And yes, I've used these two things interchangeably as this is the usual an recommended way the toolchain is used.
So your comment is groundless and factless as much of this post is.
Maybe, or just maybe that's how you choose to read it so it suits your crusade against the evil windmills.
And you assume I do not know how the engine works
You don't seem to be distinguishing between a statement of fact and a metaphor. I can't even be angry for this, just saddened.
but I do know how it works in concept
I also know how a nuclear power plant works in concept, I'm not going to be building one in my basement. "In concept" isn't knowing "in detail", sorry to break your bubble.
What I teach is using tools for what they were meant to be used for and that tool was not meant to generate Python-Qt code
I happen to know that this tool (along with its cousin the py uic) are there exactly for that reason.
Again it is obvious to me that you were not addressing the problem at hand at all
I actually had addressed the problem.
but some seem to be soap boxing an issue you have
An issue with you personally, no. As a matter of fact I suggested you don't get banned the first time around (yes, surprisingly we mods do talk to each other). On the other hand I'm not going to stand by and watch you insult the intelligence of the people visiting this forum. My place here isn't to indulge you!
and this is what is called trolling
No it is not. I have not trolled anywhere here. Moreover you've called trolls and flagged numerous people who aren't, by any conceivable measure. Have you read about one boy who cried "wolf"? If you haven't, I recommend it, granted it's a very long and complicated story but the end is a true masterpiece.
with some additional definitions in case you do not understand some of more key words being used
Nah, way too complicated for me. Can we just get back to name-calling? These were the times ...
-
Again a topic has been derailed into something completely unrelated. Please only respond to the topic if it is relevant to what the OP had asked, anything else will be removed.
And as a reminder - read the code of conduct.