Skip to content

Commit 76b586f

Browse files
committed
tkinter Notebook App demo
1 parent ef37241 commit 76b586f

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/program12.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
'''
2+
Created on Jan 14, 2018
3+
4+
@author: aditya
5+
6+
This program shows the use of notebook in tkinter
7+
Notebook is used to create Tabs in the application.
8+
This enables browsing different pages in the application.
9+
10+
Frame widget from tkinter is used in this Application to demostrate the use of Notebook/tabs.
11+
Please note that other widgets can also be used as per the requirement.
12+
'''
13+
14+
import tkinter as tk
15+
from tkinter import ttk
16+
17+
class NoteBookApp:
18+
def __init__(self, master):
19+
self.master = master
20+
self.notebk = ttk.Notebook(self.master)
21+
self.notebk.pack()
22+
self.frame1 = ttk.Frame(self.notebk, width = 400, height = 400, relief = tk.SUNKEN)
23+
self.frame2 = ttk.Frame(self.notebk, width = 400, height = 400, relief = tk.SUNKEN)
24+
self.notebk.add(self.frame1, text = 'One')
25+
self.notebk.add(self.frame2, text = 'Two')
26+
27+
self.btn = ttk.Button(self.frame1, text='Add/Insert Tab at Position 1', command = self.AddTab)
28+
self.btn.pack()
29+
30+
self.btn2 = ttk.Button(self.frame1, text='Disable Tab at Position 1', command = self.disableTab)
31+
self.btn2.pack()
32+
33+
strdisplay = r'Tab ID:{}'.format(self.notebk.select())
34+
ttk.Label(self.frame1, text = strdisplay).pack()
35+
36+
strdisplay2 = 'Tab index:{}'.format(self.notebk.index(self.notebk.select()))
37+
ttk.Label(self.frame1, text = strdisplay2).pack()
38+
39+
def AddTab(self):
40+
if self.btn['text'] == 'Add/Insert Tab at Position 1':
41+
self.frame3 = ttk.Frame(self.notebk, width = 400, height = 400, relief = tk.SUNKEN)
42+
self.notebk.insert(1, self.frame3, text = 'Additional Tab')
43+
self.btn.config(text = 'Remove/Forget Tab')
44+
else:
45+
self.notebk.forget(1)
46+
self.btn.config(text = 'Add/Insert Tab at Position 1')
47+
48+
def disableTab(self):
49+
# properties of tab - accessible by using notbook.tab(tab_id, option)
50+
# to see available properties - print(notbook.tab(tab_id))
51+
if self.btn2['text'] == 'Disable Tab at Position 1':
52+
self.notebk.tab(1, state = 'disabled')
53+
self.btn2.config(text = 'Hide Tab at Position 1')
54+
elif self.btn2['text'] == 'Hide Tab at Position 1':
55+
self.notebk.tab(1, state = 'hidden')
56+
self.btn2.config(text = 'Normalize Tab at Position 1')
57+
elif self.btn2['text']== 'Normalize Tab at Position 1':
58+
self.notebk.tab(1, state = 'normal')
59+
self.btn2.config(text = 'Disable Tab at Position 1')
60+
61+
62+
def launchNoteBookApp():
63+
root = tk.Tk()
64+
NoteBookApp(root)
65+
tk.mainloop()
66+
67+
68+
if __name__=='__main__':
69+
launchNoteBookApp()
70+
71+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy