Python Forum
[PyQt] error message
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] error message
#1
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()
Reply
#2
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
Reply
#3
(Oct-23-2022, 10:25 AM)Yoriz Wrote: 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
we have loadJsonStyle(self, self.ui)
Reply
#4
hi
I have deleted the line
from PySide2.QtWidgets import * 
and add the line
import json
and changed the line
loadJsonStyle(self, self.ui)
with the line
json.load('style.json')
but i have the error message
Error:
return loads(fp.read(), AttributeError: 'str' object has no attribute 'read'
Reply
#5
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.
the_wolf_dz likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error message box and quit app Kumarkv 1 2,215 May-19-2020, 07:05 PM
Last Post: Larz60+
  [Tkinter] How to make message box error stay on top of window scratchmyhead 1 8,119 May-10-2020, 10:21 PM
Last Post: scratchmyhead
  [PyQt] No reaction and no error message when clicking button Atalanttore 4 4,750 Nov-23-2018, 01:48 PM
Last Post: Atalanttore
  [PyQt] error message in pyqt pro red_man_008 8 7,242 Aug-13-2017, 08:50 PM
Last Post: red_man_008

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020