[PyQt] error message - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PyQt] error message (/thread-38511.html) |
error message - the_wolf_dz - Oct-23-2022 hi everybody I have created an GUI with the QT designer and when i integrate it in the python IDE ( Pycharm or Visuel Studio) I encounter the following error message " RuntimeError: You can't initialize an object twice!" and I can't understand what's the problem please help me the source code : from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.uic import loadUiType from Custom_Widgets.Widgets import * from PySide2.QtWidgets import * import os import sys MainUi,_ =loadUiType('interface.ui') class Main(QMainWindow, MainUi): def __init__(self,parent=None): super(Main, self).__init__(parent) QMainWindow.__init__(self) self.setupUi(self) loadJsonStyle(self, self.ui) def main (): app=QApplication(sys.argv) window= Main() window.show() app.exec_() if __name__ == "__main__": main() RE: error message - Yoriz - Oct-23-2022 Why do you have PyQt5 and PySide2 imports of QtWidgets? from PyQt5.QtGui import * from PyQt5.QtWidgets import * # QtWidget is imported from PyQt5 from PyQt5.QtCore import * from PyQt5.uic import loadUiType from Custom_Widgets.Widgets import * from PySide2.QtWidgets import * # QtWidget is imported from PySide2 RE: error message - the_wolf_dz - Oct-24-2022 (Oct-23-2022, 10:25 AM)Yoriz Wrote: Why do you have PyQt5 and PySide2 imports of QtWidgets?we have loadJsonStyle(self, self.ui) RE: error message - the_wolf_dz - Oct-24-2022 hi I have deleted the line from PySide2.QtWidgets import *and add the line import jsonand changed the line loadJsonStyle(self, self.ui)with the line json.load('style.json')but i have the error message
RE: error message - deanhystad - Oct-24-2022 json.load() expects a file pointer, not a file name. https://docs.python.org/3/library/json.html Not that it matters. You don't want to load a json file, you want to load a json file and apply the style object it creates. You really want to use loadJsonStyle() which is imported by: from Custom_Widgets.Widgets import *I was looking at the custom widgets project on pypl. All the examples I looked at use PySide2. Widgets.py and WidgetsWorker.py reference PySide2 or PySide6. I don't think you can use PyQt5. PyQt5 and PySide6 are very similar, so you can probably "port" this to Qt5, but if you are just starting out I suggest using PySide6. |