Code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
coulbg = "dark grey"
coultxt = "black"
winx = "1024"
winy = "576"
import tkinter
from tkinter import ttk
from tkinter.filedialog import *
class InterGeneric(tkinter.Tk): # this class manages the pages, and the upper part of the interface with the tabs to swith pages
def __init__(self, *args, **kwargs):
tkinter.Tk.__init__(self, *args, **kwargs)
self.minsize(width=winx, height=winy)
self.grid()
self.resizable(True, True)
container = tkinter.Frame(self)
container.grid()
self.frames = {}
for F in (PageOne, PageTwo):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
frame.grid(row=1, column=0, sticky="nsew")
self.show_frame("PageOne", self)
def show_frame(self, page_name, controller):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
self.update()
self.geometry(self.geometry())
self.controller = controller
self.columnconfigure(0, weight=6)
self.columnconfigure(1, weight=1)
self.rowconfigure(1, weight=1)
frame_up = tkinter.Frame(self, bg="green", height=50, borderwidth=0) # upper part of the window, with all buttons in a green frame
frame_up.grid(column=0, row=0, sticky="we")
but_cfg = dict(borderwidth=1, fg='grey', bg='black', activeforeground='grey99', activebackground='black')
but_one = Button(frame_up, text="-> Page One", command=lambda: controller.show_frame("PageOne"), **but_cfg)
but_one.grid(column=0, row=0, padx=10, pady=10, sticky="nsew") # button to go to PageOne
but_two = Button(frame_up, text="-> Page Two", command=lambda: controller.show_frame("PageTwo"), **but_cfg)
but_two.grid(column=1, row=0, padx=10, pady=10, sticky="nsew") # button to go to PageTwo
frame_upq = tkinter.Frame(self, bg="purple", height=50, borderwidth=0) # frame top right with Quit button
frame_upq.grid(column=2, row=0, sticky="we")
but_quitter = Button(frame_upq, text="-> Quit", command=self.quit, **but_cfg)
but_quitter.grid(column=0, row=0, padx=10, pady=10, sticky="e") # button to quit
for i in range(2):
frame_up.grid_columnconfigure(i, weight=1)
frame_up.grid_rowconfigure(0, weight=1)
frame_upq.grid_columnconfigure(0, weight=1)
frame_upq.grid_rowconfigure(0, weight=1)
class PageOne(tkinter.Frame):
def __init__(self, parent, controller):
tkinter.Frame.__init__(self, parent)
self.controller = controller
frame_pageone = tkinter.Frame(self, bg="blue", height=200) # should be PageOne full of blue
class PageTwo(tkinter.Frame):
def __init__(self, parent, controller):
tkinter.Frame.__init__(self, parent)
self.controller = controller
frame_pagetwo = tkinter.Frame(self, bg="red", height=200) # should be PageTwo full of red
if __name__ == "__main__":
app = InterGeneric()
app.title("DraDro_160524.01")
app.mainloop()