-3

When I run this code, I get an error stating that : AttributeError: 'bool' object has no attribute 'specificaccount_radiobutton'

from PySide6.QtWidgets import (QGroupBox, QGridLayout, QLabel, QRadioButton,
                               QComboBox, QHBoxLayout)

class Banking():
    def __init__(self) -> None:
        global all_accounts_selected
        global specific_account_selected

        all_accounts_selected = Banking.all_accounts_selected
        specific_account_selected = Banking.specific_account_selected

    def Draw(self):
        self.bankaccounts_groupbox = QGroupBox("Banking")
        self.bankaccounts_layout = QGridLayout(self.bankaccounts_groupbox)

        self.bankaccounts_layout.addWidget(self.Filter(), 0, 0)

        self.bankaccounts_groupbox.setFixedHeight(500)
        return self.bankaccounts_groupbox
    
    def Filter(self):
        self.filter_groupbox = QGroupBox()
        self.filter_layout = QHBoxLayout(self.filter_groupbox)


        self.allaccounts_radiobutton = QRadioButton("All")
        self.allaccounts_radiobutton.setChecked(True)
        self.allaccounts_radiobutton.toggled.connect(all_accounts_selected)
        self.specificaccount_radiobutton = QRadioButton("Specific")
        self.specificaccount_radiobutton.toggled.connect(specific_account_selected)

        self.specificaccount_combobox = QComboBox()
        self.specificaccount_combobox.setEnabled(False)

        
        self.filter_layout.addWidget(self.allaccounts_radiobutton)
        self.filter_layout.addWidget(self.specificaccount_radiobutton)
        self.filter_layout.addWidget(self.specificaccount_combobox)
        self.filter_layout.addStretch(1)
        
        self.filter_groupbox.setFixedHeight(self.filter_groupbox.sizeHint().height())
        return self.filter_groupbox
    
    def all_accounts_selected(self, *args):
        print("test1")
        self.specificaccount_radiobutton.setEnabled(False)
        self.specificaccount_combobox.clear()

    def specific_account_selected(self, *args):
        print("test2")
        self.specificaccount_radiobutton.setEnabled(True)
        self.specificaccount_combobox.addItems(["test1", "tes2"])

This seems weird since specificaccount_radiobutton is a radio button and not a boolean. I am new to qt switching over from dearpygui and I have never encounteredthis before

relu
  • 11
  • 2
  • As already suggested in your other post, you really need to learn to properly use classes and instances, and also avoid using globals, especially as some sort of function aliases, as it really doesn't make any sense. – musicamante Aug 14 '23 at 18:12
  • that's extremely helpful thank you – relu Aug 14 '23 at 18:38
  • When you run this code nothing will happen. It's just imports and a class definition. Please make a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). All we can say about the current code is that you're doing some very strange things. – mahkitah Aug 14 '23 at 19:11

1 Answers1

-1

You need to move input initialization

self.allaccounts_radiobutton = QRadioButton

from def filer() to class constructor init. Before call Banking.all_accounts_selected

Dmytro
  • 9
  • 1
  • The problem was about poor implementation and bad usage of object attributes (including function references) which causes problems in the order of arguments when the connected function is called. It has nothing to do with what you're pointing out. – musicamante Aug 16 '23 at 12:57