Creating our FriendsList class
Begin with a new folder, which will hold all of the code for our chat application. Inside this folder, create a file called friendslist.py. In this file, we will begin writing our FriendsList class:
import tkinter as tk
import tkinter.ttk as ttk
class FriendsList(tk.Tk):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.title('Tk Chat')
self.geometry('700x500')
self.canvas = tk.Canvas(self, bg="white")
self.canvas_frame = tk.Frame(self.canvas)
self.scrollbar = ttk.Scrollbar(self, orient="vertical",
command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.scrollbar.set)
self.scrollbar.pack(side=tk.LEFT, fill=tk.Y)
self.canvas.pack(side=tk.LEFT, expand=1, fill=tk.BOTH)
self.friends_area = self.canvas.create_window((0, 0),
window=self.canvas_frame, anchor="nw")
self.bind_events()
self.load_friends()Hopefully everything here looks very familiar. We import the usual...