Tying it all together

Let's begin with the ability to add a friend, since we need this to make the rest of our changes work properly.

We already have a Friends menu in the top menu bar of our FriendsList class containing an Add Friend command, which seems appropriate for this functionality. We'll replace the placeholder method with a functioning one:

def __init__(self, **kwargs):    ...    self.friends_menu.add_command(label="Add Friend", command=self.show_add_friend_window)    ...def show_add_friend_window(self):    AddFriendWindow(self)

In order to take the information, we need to add a friend and we will require a new Toplevel window. Go ahead and create a file named addfriendwindow.py alongside your friendslist.py file:

import tkinter as tkimport ...

Get Tkinter GUI Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.