Navigating Through Multiple Pages in a Modern Tkinter Window | Sleek Toggle Menu Design | Creating a Modern GUI with Tkinter | Part 1

Posted by

Switch Multiple Pages in Tkinter Modern Window | Modern Toggle Menu | Tkinter Modern GUI | Part 1

Switch Multiple Pages in Tkinter Modern Window

In this tutorial, we will learn how to switch between multiple pages in a Tkinter modern window. We will also create a modern toggle menu to navigate between the pages.

Creating the Tkinter Modern GUI

First, let’s create a Tkinter window with a modern look. We will use the ttk.Notebook widget to display multiple pages within the window.

“`html

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.title("Tkinter Modern GUI")

# Create a ttk.Notebook widget
notebook = ttk.Notebook(root)
notebook.pack(fill='both', expand=True)

# Create multiple pages
page1 = ttk.Frame(notebook)
page2 = ttk.Frame(notebook)
page3 = ttk.Frame(notebook)

notebook.add(page1, text='Page 1')
notebook.add(page2, text='Page 2')
notebook.add(page3, text='Page 3')

root.mainloop()

“`

Creating the Modern Toggle Menu

Next, let’s create a modern toggle menu to switch between the pages. We will use a ttk.Combobox widget to display the menu options.

“`html

# Create a ttk.Combobox widget
menu_options = ['Page 1', 'Page 2', 'Page 3']
menu_var = tk.StringVar()
menu = ttk.Combobox(root, textvariable=menu_var, values=menu_options)
menu.pack()

# Function to switch pages
def switch_page():
    selected_page = menu_var.get()
    if selected_page == 'Page 1':
        notebook.select(page1)
    elif selected_page == 'Page 2':
        notebook.select(page2)
    elif selected_page == 'Page 3':
        notebook.select(page3)

# Call the switch_page function when a menu option is selected
menu.bind('<>', lambda e: switch_page())

“`

Conclusion

By following the steps outlined in this tutorial, you can easily switch between multiple pages in a Tkinter modern window using a toggle menu. Stay tuned for Part 2, where we will add more functionality to the GUI!

0 0 votes
Article Rating
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@tkinterhub
1 month ago

Part 2 Video:-
Coming Soon..

@MennChanrattanak
1 month ago

Please release video Part 2 and final of Switch Multiple Pages in Tkinter Modern Window….

@mir_intizam
1 month ago

Like

@digitalmachine0101
1 month ago

Good information