Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create function module and connect in with menu.py
Forum Update on Monday, May 27th 2025

How to create function module and connect in with menu.py

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 188 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chaikovskyii
    wrote on 17 Apr 2022, 21:28 last edited by chaikovskyii
    #1

    I'm so sorry, I'm new to pyqt5 and qt designer, maybe this is a stupid question but help me pls..
    The problem is that I'm getting circular import error since in menu.py I'm importing functions.py and in functions.py I am importing menu.py

    So this is my menu.py

    from PyQt5 import QtCore, QtGui, QtWidgets
    import functions
    
    class CompleterDelegate(QtWidgets.QStyledItemDelegate):
        def initStyleOption(self, option, index):
            super(CompleterDelegate, self).initStyleOption(option, index)
            # option.font.setFamily('Montserrat')
            # option.palette.setBrush(QtGui.QPalette.Text, QtGui.QColor(112,112,112))
            option.font.setBold(True)
            option.displayAlignment = QtCore.Qt.AlignCenter
    
    
    class Ui_Menu(object):
        def get_data(self, model):
            model.setStringList( ["one", "two", "three", "four", "python", "pyqt", "vasyl petrovych"] )
    
       "this is a function i want to import from functions.py"
        #def move_symptom(self):
        #    selected = self.symptoms_list.currentItem().text()
        #    item = QtWidgets.QListWidgetItem()
        #    self.symptoms_list.takeItem(self.symptoms_list.currentRow() )
        #    self.selected_symptoms_list.addItem( item )
        #    item.setText( selected )
        #    self.symptoms_list.clearSelection()
    ...
    ...
    ...
    

    and this is my functions.py

    import menu
    from PyQt5 import QtCore, QtGui, QtWidgets
    
    
    class AppFunctions(menu.Ui_Menu):
        def move_symptom(self):
            selected = menu.ui.self.symptoms_list.currentItem().text()
            item = QtWidgets.QListWidgetItem()
            menu.ui.self.symptoms_list.takeItem(menu.ui.self.symptoms_list.currentRow())
            menu.ui.self.selected_symptoms_list.addItem( item )
            item.setText( selected )
            menu.ui.self.symptoms_list.clearSelection()
    

    Thanks in advance!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 Apr 2022, 16:37 last edited by
      #2

      Hi,

      You should move your code so that you don't need that circular import.

      That said, code generated from designer definition shall not be modified. You usually import these file in your own code that will build stuff on top of it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      1/2

      17 Apr 2022, 21:28

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved