Python Forum
[Tkinter] Auto re-fit frames sizes in main window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Auto re-fit frames sizes in main window
#1
I have the menu frame on the left side and the main container on the right side but when I fire it up I only see them in a small box inside the main window.

How can I make the frames fit the window no matter what size it is?

[Image: Dko4T.jpg]

class GUI(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.title("GUI Project")
        # self.resizable(0, 0)
        menu = tk.Frame(self, relief="solid")
        container = tk.Frame(self, relief="ridge")
        menu.grid(row=0, column=0, rowspan=4, sticky="nsew")
        container.grid(row=0, column=1, sticky="nsew")
        menu.grid_rowconfigure(0, weight=1)
        container.rowconfigure(0, weight=0)
        container.columnconfigure(1, weight=0)

        self.frames = ["Menu", "FutureFeature2", "TestPing", "FutureFeature3", "FutureFeature"]

        self.frames[0] = Menu(parent=menu, controller=self)
        self.frames[1] = FutureFeature2(parent=container, controller=self)
        self.frames[2] = TestPing(parent=container, controller=self)
        self.frames[3] = FutureFeature3(parent=container, controller=self)
        self.frames[4] = FutureFeature(parent=container, controller=self)

        self.frames[0].grid(row=0, column=0, sticky="nsew")
        self.frames[1].grid(row=0, column=0, sticky="nsew")
        self.frames[2].grid(row=0, column=0, sticky="nsew")
        self.frames[3].grid(row=0, column=0, sticky="nsew")
        self.frames[4].grid(row=0, column=0, sticky="nsew")

        self.show_frame(1)

    def show_frame(self, page_name):
        frame = self.frames[page_name]
        print(frame)
        frame.tkraise()
        frame.grid(row=0, column=0, columnspan=5, rowspan=5, sticky="nsew")

class Menu(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller

        button1 = tk.Button(self, text="Ping Test", bg="royalblue2",
                            command=lambda: controller.show_frame(2))
        button2 = tk.Button(self, text="FutureFeature", bg="dark violet",
                            command=lambda: controller.show_frame(4))
        buttun3 = tk.Button(self, text="FutureFeature", bg="pale goldenrod",
                            command=lambda: controller.show_frame(1))
        button4 = tk.Button(self, text="Quit", bg="gray40",
                            command=lambda: self.terminate())

        button1.pack(fill="both", expand=True)
        button2.pack(fill="both", expand=True)
        buttun3.pack(fill="both", expand=True)
        button4.pack(fill="both", expand=True)

    def terminate(self):

        path = fr'c:/users/{os.getlogin()}/desktop/Gui-Skeleton'

        try:
            os.rmdir(path)
        except OSError as err:
            print(f"Error Deleting tmp folder! {err}")

        exit()

if __name__ == "__main__":

    path = fr'c:/users/{os.getlogin()}/desktop/Gui-Skeleton'

    try:
        if os.path.isdir(path):
            pass
        else:
            os.mkdir(path)

    except OSError as err:
        print(f"[!] Operation failed! {err}")

    app = GUI()
    app.geometry("800x600")
    app.mainloop()
Reply
#2
Have a look at this tutorial.
https://python-forum.io/Thread-Tkinter-G...first-time
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 341 Mar-17-2024, 09:37 AM
Last Post: deanhystad
Exclamation [Tkinter] Error when closing the main window with destroy TomasSanchexx 1 727 Aug-06-2023, 01:54 AM
Last Post: deanhystad
  [PyQt] Can't get MDIarea to resize automatically with Main Window JayCee 4 3,395 Aug-02-2021, 08:47 PM
Last Post: JayCee
Thumbs Up tkinter canvas; different page sizes on different platforms? philipbergwerf 4 4,034 Mar-27-2021, 05:04 AM
Last Post: deanhystad
  [PyQt] How to clip layout to sides and bottom of main window? Valmont 9 4,838 Mar-24-2021, 10:00 PM
Last Post: deanhystad
  "tkinter.TclError: NULL main window" Rama02 1 5,781 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  [Tkinter] Hi, Keep postition of main window after iconify() delphinis 3 3,052 Jul-12-2020, 06:59 AM
Last Post: DT2000
  [Tkinter] How to add multiple frames to main window Dandy_Don 13 7,776 Apr-29-2020, 09:21 PM
Last Post: Dandy_Don
  tkinter window and turtle window error 1885 3 6,619 Nov-02-2019, 12:18 PM
Last Post: 1885
  “main thread is not in main loop” in Tkinter Long_r 1 24,078 Jun-26-2019, 11:00 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020