1

When the calendar is clicked, it tries to pass a value to def Calendar_click (self, date): value in class Tab1 (QWidget): def ViewTable (self) :. I tried to specify parameters, I also specified global variables, but I did not receive the data. def MotherInformation (self): I continue to refer to tabs.addTab (Tab1 (), 'TAB1') in the function. How do I fix it?

TypeError: ViewTable() missing 1 required positional argument: 'caldate'
class main_window(QWidget):
    def __init__(self):
        super(main_window, self).__init__()
        ...

    def Calendar(self):
        self.cal = QCalendarWidget(self)
        self.cal.setGridVisible(True)
        vbox = QVBoxLayout()
        vbox.addWidget(self.cal)
        self.calGroup = QGroupBox(title='day')
        self.calGroup.setLayout(vbox)
        self.cal.clicked.connect(self.Calendar_click)

    def Calendar_click(self, date):
        global calendarDate
        calendarDate = date
        # Tab1().ViewTable(date)
        # calendarDate = QDate.toPyDate(date)

    def MotherInformation(self):    
        vbox.addWidget(tabs)
        tabs.addTab(Tab1(), 'TAB1') # this value -> Class Tab1 ??
        tabs.addTab(QPushButton(), 'TAB2')
        self.lineGroup1.setLayout(vbox)

class Tab1(QWidget):
    def __init__(self):
        super(Tab1, self).__init__()
        self.ViewTable()

    def ViewTable(self, caldate):
        print(caldate)
        tab1TableWidget = QTableWidget()
        tab1TableWidget.resize(613,635)
        tab1TableWidget.horizontalHeader()
        tab1TableWidget.setRowCount(100)
        tab1TableWidget.setColumnCount(100) 
eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

1

You have to save the reference of the created Tab1 object and use it when necessary:

def Calendar_click(self, date):
    self.tab1.ViewTable(date)

def MotherInformation(self):
    self.tab1 = Tab1()  # save reference
    vbox.addWidget(tabs)
    tabs.addTab(self.tab1, 'TAB1')
    tabs.addTab(QPushButton(), 'TAB2')
    self.lineGroup1.setLayout(vbox)

Another error you have is that you are invoking ViewTable() method in the Tab1 constructor unnecessarily, changing to:

class Tab1(QWidget):
    def ViewTable(self, caldate):
        print(caldate)
        tab1TableWidget = QTableWidget()
        tab1TableWidget.resize(613,635)
        tab1TableWidget.horizontalHeader()
        tab1TableWidget.setRowCount(100)
        tab1TableWidget.setColumnCount(100) 
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thank you for answer I tried it the way you told me. `TypeError: ViewTable () missing 1 required positional argument: 'calDate'` error message is displayed. It works fine when calling a function that has no value. When I pass the date value to `class Tab1 (QWidget):` it just closes the window or gives an error. What if I think of a way to turn it into a global variable? – 인정병원 Apr 17 '19 at 04:17
  • @인정병원 Do not abuse the global variables, they are not necessary in this case: https://stackoverflow.com/questions/19158339/why-are-global-variables-evil – eyllanesc Apr 17 '19 at 04:24