Introduction
In this blog, I am going to create a tabbed widget in a Python GUI application. It will display the tabbed window on the application screen.
Software requirement
Python 3.5 and IDLE (Python 3.5)
Programming code
-
- import tkinter as tk
- from tkinter import ttk
- win = tk.Tk()
- win.title("Python GUI App")
-
- tabControl=ttk.Notebook(win)
-
- tab1=ttk.Frame(tabControl)
- tabControl.add(tab1, text='Tab 1')
-
- tab2=ttk.Frame(tabControl)
- tabControl.add(tab2, text='Tab 2')
- tabControl.pack(expand=1, fill="both")
-
- ttk.Label(tab1, text="This is Tab 1").grid(column=0,row=0,padx=10,pady=10)
- ttk.Label(tab2, text="This is Tab 2").grid(column=0,row=0,padx=10,pady=10)
-
- win.mainloop()
About the code
- First, I am importing the tkinter modules.
- Next, I assign a class and variables and give the application title.
- Next, I create a tab control and two tabs in the code.
- Finally, I have started the Windows event loop by calling the main loop method; then, I executed the code.
Output