#๐ My GUI freezes every time I run a function
21 messages ยท Page 1 of 1 (latest)
@abstract cliff
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Hey, so the problem is that my function has to use internet to load some info, and while it is loading the GUI freezes
ask if you need me to explain what a part of the code does
!paste -- Send the code here.
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
yeah, I tried that, says my code exeeds 512kb
even tho it is 168kb
Ah, PyQt, I see.
yep
My first suggestion would be to not use uic since the code it generates is frankly... quite bad. Instead, use QtUic to load your UI directly (I think that's how it's called in PyQt?).
This is generally why I avoid qt designer
But I cant do that now, I changed wayyy too much of the code
Anyways, the actual issue here is that you're running the code on the same thread as your GUI. So, if something blocks that UI (like with what would happen with a request), the UI will appear "frozen" because no events are being sent to it and the OS will interpret that as the window "not responding."
Basically, use threads. In PyQt/PySide, there's QThread for this plus a nice interface around it called QRunnable.
https://www.pythonguis.com/tutorials/multithreading-pyqt-applications-qthreadpool/
Here's a nice tutorial about it.
alright, I'll try
should I let you know if I have any problems?
Even if you want to use uic, this is not the correct way of doing it.
You aren't supposed to modify its outputs as implied by the comment:
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
You are supposed to have a separate file for the UI you generated and a separate file that loads it into your actual application.
from PyQt5.QtWidgets import QMainWindow
from .uic_file import Ui_MainWindow # or whatever it's called
class Window(QMainWindow, Ui_MainWindow):
def __init__(self) -> None:
super().__init__() # add the actual logic for the UI
There's also loading the UI directly through uic although that loses the autocomplete benefits.
Qt Designer is useful only if you know how to use it properly and if the thing you're looking for is a quick UI and you only care about app logic. If you're looking into learning the inner workings of Qt, I would stay away from it (and once you learn enough Qt, you might even find that easier than Designer).
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.