-
Notifications
You must be signed in to change notification settings - Fork 0
/
texttabs.py
57 lines (41 loc) · 1.54 KB
/
texttabs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from tkinter import *
from tkinter import ttk
class TextTab(Frame):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# variables
self.tabs: dict[str: Text] = {}
self.activetab = "default"
# change variables
for k, v in kwargs.setdefault("attrs", {}).items():
self.__setattr__(k, v)
# create widgets
self.header = Frame(self, height=30, width=self.winfo_width() - 1)
self.tabframe = Frame(self)
self.createtab(self.activetab)
self.createtab("n2")
# pack widgets
self.header.pack(fill=X, side=TOP)
self.tabframe.pack(fill=BOTH, expand=True, side=BOTTOM)
self.update()
def createtab(self, name):
self.tabs[name] = Text(self.tabframe)
def update(self):
for i in self.tabs.values():
i.pack_forget()
try:
self.tabs[self.activetab].pack(fill=BOTH, expand=True)
except KeyError:
self.tabs[list(self.tabs.keys())[0]].pack(fill=BOTH, expand=True)
for i in self.header.children.copy().values():
i.destroy()
for i in self.tabs.keys():
b = ttk.Button(self.header, text=i, command=lambda *a: (self.__setattr__(self.activetab, i), self.update()))
b.pack(side=RIGHT)
super().update()
if __name__ == "__main__":
root = Tk()
f = TextTab(root)
f.pack()
print(dir(f))
root.mainloop()