If using a store-bought pie crust, follow package instructions to bake it until golden. Let it cool completely.
In a medium saucepan, whisk together the granulated sugar, flour, and salt. Gradually whisk in the milk until well combined. Place the saucepan over medium heat and stir continuously until the mixture thickens and comes to a boil (about 10 minutes).
In a small bowl, lightly beat the egg yolks. Once the custard has thickened, gradually add a bit of the hot mixture to the egg yolks, whisking constantly to prevent curdling. Then, pour the warmed egg yolk mixture back into the saucepan with the custard.
Cook the custard for an additional 2-3 minutes, stirring until thickened. Remove from heat and stir in the butter and vanilla extract. Transfer the custard to a bowl and cover with plastic wrap directly on the surface to prevent a skin from forming. Let it cool to room temperature.
Slice the bananas and place them evenly over the bottom of the cooled pie crust. Pour the cooled custard over the bananas, spreading it evenly.
In a mixing bowl, whip the heavy cream and powdered sugar until soft peaks form. Spread the whipped cream on top of the custard layer.
Cover the pie with plastic wrap and refrigerate for at least 4 hours, preferably overnight, to allow the flavors to meld and the pie to set.
Slice the pie and enjoy! Optionally garnish with extra banana slices or chocolate shavings if desired.