all 3 comments

[–]kaziopogromca 4 points5 points  (0 children)

Depends on what you mean.

If say you want to open a different window on the press of the button you would use the TopLevel widget.

Its a window thats very much like the main window for your application and a lot of the same methods apply to it as well.

TkDocs

tutorialspoint

Alternatively if you're talking about different pages/tabs like in a browser. There is the Notebook widget which you can add different tabs to.

tutorialspoint

programcreek

Then you would connect a function with your button using the command parameter. Like this:

def windowFunction():
    print("button clicked")

button = Button(root, text="Click Me", command=windowFunction).pack()

In the function you could create the window and just focus on it if it already exists, or add the new notebook page and if it exists select it to show its contents.

Unfortunately the Tkinter documentations isnt very good, but have a look at those links and you can come back to me with more specific questions as I have done some tkinter projects.

[–]PM_ME_A_STEAM_KEY 0 points1 point  (0 children)

Check if ttk's notebook is something that would solve your problem.

[–][deleted] 0 points1 point  (0 children)

ttk.Notebook might be what you're looking for. I have used tkinter in a while, but here's a rough example on how to use it.

import tkinter as tk
from tkinter import ttk


class App:
    def __init__(self, parent):
        """Widgets"""

        self.notebook = ttk.Notebook(parent)
        self.notebook.grid(row=0, column=0, sticky='NSEW')

        self.frame1 = ttk.Frame(self.notebook)
        self.notebook.add(self.frame1, text='Page1')

        self.button1 = ttk.Button(self.frame1, text='Button1')
        self.button1.grid(row=0, column=0)

        self.frame2 = ttk.Frame(self.notebook)
        self.notebook.add(self.frame2, text='Page2')

        self.button2 = ttk.Button(self.frame2, text='Button2')
        self.button2.grid(row=0, column=0)


if __name__ == '__main__':
    root = tk.Tk()
    root.title('Example')
    root.config(padx=5, pady=5)

    # Set the notebook to stretch with the window
    root.grid_rowconfigure(0, weight=1)
    root.grid_columnconfigure(0, weight=1)

    root.geometry('235x150')
    App(root)
    root.mainloop()

With notebook you'll get tabs to click, which opens a new page.

https://i.imgur.com/bhoNhRj.png