Oct-07-2016, 06:18 PM
I would like to be consistent in my window management (I heard that was best practice). However, I have a window that is 800x400 which is the size of my touch screen and I can't get the page objects to fill the window. Any help is very much appreciated.
Thanks,
neech
import tkinter as tk class Page(tk.Frame): def __init__(self, *args, **kwargs): tk.Frame.__init__(self, *args, **kwargs) # end of __init__() def show(self): self.lift() # end of show() # end of Page class class Page1(Page): mode_val = 0 def __init__(self, *args, **kwargs): Page.__init__(self, *args, **kwargs) label = tk.Label(self, text="this is page 1") label.grid(row=0, column=0) # end of __init__() # end of Page1 class class Page2(Page): def __init__(self, *args, **kwargs): Page.__init__(self, *args, **kwargs) label = tk.Label(self, text="this is page 2") label.grid(row=0, column=0) # end of __init__() # end of Page2 class class MainView(tk.Frame): def __init__(self, *args, **kwargs): tk.Frame.__init__(self, *args, **kwargs) self.rowconfigure(0,weight=1) self.rowconfigure(1,weight=1) # this is the container for the sub pages container = tk.Frame(self, borderwidth=2, relief=tk.GROOVE, height=400, width=600) # sub pages p1 = Page1(container) p2 = Page2(container) # buttons to the left of the screen b1 = tk.Button(self, text="Page 1", command=p1.show, width=8, height=2) b2 = tk.Button(self, text="Page 2", command=p2.show, width=8, height=2) b3 = tk.Button(self, text=" ", command=self.pass_function, width=8, height=2) b4 = tk.Button(self, text=" ", command=self.pass_function, width=8, height=2) b5 = tk.Button(self, text=" ", command=self.pass_function, width=8, height=2) b6 = tk.Button(self, text=" ", command=self.pass_function, width=8, height=2) b7 = tk.Button(self, text=" ", command=self.pass_function, width=8, height=2) b8 = tk.Button(self, text=" ", command=self.pass_function, width=8, height=2) # attach buttons to grid buttons = [b1, b2, b3, b4, b5, b6, b7, b8] button_index = 0 for b in buttons: b.grid(row=button_index, column=0, padx=5, pady=4) button_index = button_index + 1 # end of for loop # adding container and pages to grid container.grid(row=0, column=1, rowspan=8, sticky=tk.N+tk.S+tk.E+tk.W) p1.grid(row=0, column=0) p2.grid(row=0, column=0) # show the first page initially p1.show() # end of init def pass_function(self): pass # end of pass_function() # end of mainview class if __name__ == '__main__': root = tk.Tk() root.geometry("800x400") mv = MainView(root) mv.grid(row=0, column=0) root.mainloop() # end of main
neech