Using Tabbed Widget In Python GUI Application


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
  1. #Create Tabbed widget in Python GUI Application  
  2. import tkinter as tk  
  3. from tkinter import ttk  
  4. win = tk.Tk()  
  5. win.title("Python GUI App")  
  6. #Create Tab Control  
  7. tabControl=ttk.Notebook(win)  
  8. #Tab1  
  9. tab1=ttk.Frame(tabControl)  
  10. tabControl.add(tab1, text='Tab 1')  
  11. #Tab2  
  12. tab2=ttk.Frame(tabControl)  
  13. tabControl.add(tab2, text='Tab 2')  
  14. tabControl.pack(expand=1, fill="both")  
  15. #Tab Name Labels  
  16. ttk.Label(tab1, text="This is Tab 1").grid(column=0,row=0,padx=10,pady=10)  
  17. ttk.Label(tab2, text="This is Tab 2").grid(column=0,row=0,padx=10,pady=10)  
  18. #Calling Main()  
  19. 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.