I want to navigate through different pages(frames) on my TKinter interface using buttons. First I need a grid that is evenly distributed over the interface so that I can place widgets accordingly on the frame.
To do this I wrote the following code:
import tkinter as tk
from tkinter import ttk
class App(tk.Tk):
def __init__(self):
super().__init__()
# Create interface.
self.geometry("600x300")
self.title('login')
self.resizable(0,0)
# Create 5x5 grid for the interface.
for cel in range(5):
self.columnconfigure(cel, weight=1)
self.rowconfigure(cel, weight=1)
# Create a homepage frame.
self.HomeFrame = ttk.Frame(self)
self.HomeFrame.grid(column=0, row = 0, sticky='nswe')
# Create 5x5 grid for the homepage frame.
for cel in range(5):
self.HomeFrame.columnconfigure(cel, weight=1)
self.HomeFrame.rowconfigure(cel ,weight=1)
# Create a label for each cel in the 5x5 HomeFrame Grid.
# Change `self.HomeFrame` with `self` to see the grid of the interface
for column in range(5):
for row in range(5):
self.rowlabel = ttk.Label(self, text=(str(column), str(row)))
self.rowlabel.grid(column=column, row=row)
if __name__ == "__main__":
app = App()
app.mainloop()
Both grids are generated in the same way, but the result is different. I added numbers in each cel to show the difference.
This is what the grid looks like on my interface.
This is what the grid looks like on my frame
How do I generate the same grid for a frame?
Edit: Eventually I want to place buttons on the cells '01 - 04'. Then, I want to place a frame for each button on cel '1 0' that stretches out to '4 4' and changes to the corresponding button being clicked.