Now that we have a basic window set, we might have the urge to make it look a little better. Right now, our buttons especially are quite ugly. To do some minor updates to the graphics quite easily, we can make use of ttk.
To start, we need to import it:
from tkinter import ttk
Next, within our SeaofBTCapp:
class SeaofBTCapp(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) tk.Tk.iconbitmap(self,default='clienticon.ico') tk.Tk.wm_title(self, "Sea of BTC Client")
While the above isn't about ttk, we're doing this to change the window icon, as well as the window's title.
Next, within our StartPage:
class StartPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self,parent) label = ttk.Label(self, text="Start Page", font=LARGE_FONT) label.pack(pady=10,padx=10) # change the tk to ttk button = ttk.Button(self, text="Visit Page 1", command=lambda: controller.show_frame(PageOne)) button.pack() # change the tk to ttk button2 = ttk.Button(self, text="Visit Page 2", command=lambda: controller.show_frame(PageTwo)) button2.pack()
Here, we are mainly just changin tk.Button to ttk.Button. That's just one example, but you should change all of your buttons from tk to ttk.
Here's the full script:
# The code for changing pages was derived from: http://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter # License: http://creativecommons.org/licenses/by-sa/3.0/ import tkinter as tk from tkinter import ttk LARGE_FONT= ("Verdana", 12) class SeaofBTCapp(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) tk.Tk.iconbitmap(self,default='clienticon.ico') tk.Tk.wm_title(self, "Sea of BTC Client") container = tk.Frame(self) container.pack(side="top", fill="both", expand = True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {} for F in (StartPage, PageOne, PageTwo): frame = F(container, self) self.frames[F] = frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame(StartPage) def show_frame(self, cont): frame = self.frames[cont] frame.tkraise() class StartPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self,parent) label = ttk.Label(self, text="Start Page", font=LARGE_FONT) label.pack(pady=10,padx=10) button = ttk.Button(self, text="Visit Page 1", command=lambda: controller.show_frame(PageOne)) button.pack() button2 = ttk.Button(self, text="Visit Page 2", command=lambda: controller.show_frame(PageTwo)) button2.pack() class PageOne(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) label = ttk.Label(self, text="Page One!!!", font=LARGE_FONT) label.pack(pady=10,padx=10) button1 = ttk.Button(self, text="Back to Home", command=lambda: controller.show_frame(StartPage)) button1.pack() button2 = ttk.Button(self, text="Page Two", command=lambda: controller.show_frame(PageTwo)) button2.pack() class PageTwo(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) label = ttk.Label(self, text="Page Two!!!", font=LARGE_FONT) label.pack(pady=10,padx=10) button1 = ttk.Button(self, text="Back to Home", command=lambda: controller.show_frame(StartPage)) button1.pack() button2 = ttk.Button(self, text="Page One", command=lambda: controller.show_frame(PageOne)) button2.pack() app = SeaofBTCapp() app.mainloop()