How to share variable between def in class? [duplicate]

You can set it as self.board. Like this:

class MainWindow(QtWidgets.QMainWindow):         

    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

    def buttonClicked5(self):  
        self.board = Arduino(self.ui.comboBox.currentText())
        communication_start = "Communication Successfully started"
        self.ui.lineEdit_4.setText(communication_start)

    def closeEvent(self, event):
        self.board.exit()