Skip to content

Instantly share code, notes, and snippets.

@duangsuse
Created September 1, 2020 08:46
Show Gist options
  • Save duangsuse/924f52435e8a001ba63fb4834f582757 to your computer and use it in GitHub Desktop.
Save duangsuse/924f52435e8a001ba63fb4834f582757 to your computer and use it in GitHub Desktop.
Removed from TkGUI
class CollapseFrame(Frame):
def __init__(self, parent, expanded_text ="Collapse <<", collapsed_text ="Expand >>"):
super().__init__(parent)
self.parent = parent
self._expanded_text = expanded_text
self._collapsed_text = collapsed_text
self.columnconfigure(1, weight = 1) #grow in grid
self._variable = BooleanVar(value=False)
self._button = Button(self, command = self.toggle)
self._button.grid(row = 0, column = 0)
self._separator = Separator(self, orient=HORIZONTAL)
self._separator.grid(row = 0, column = 1, sticky ="we")
self.frame = Frame(self)
self._activate()
def _activate(self):
def setText(text): self._button["text"] = text
if not self._variable.get():
self.frame.grid_forget()
setText(self._collapsed_text)
else:
# increasing the frame area, reside new widgets
self.frame.grid(row = 1, column = 0, columnspan = 2)
setText(self._expanded_text)
def toggle(self):
self._variable.set(not self._variable.get())
self._activate()
class TkGUI:
class SeparatorFrame(Frame):
def __init__(self, parent, text, fill, *args, **kwargs):
self.text,self.fill = text,fill
super().__init__(parent, *args, **kwargs)
def pack(self, *args, **kwargs):
if self.text != None: Label(self, text=self.text).pack()
del kwargs["fill"]
super().pack(*args, fill=self.fill, expand=(self.fill == BOTH), **kwargs)
def separator(p, text=None, fill=X, height=2, bg="white", relief=FLAT):
extras = {} if useTheme else {"bg":bg, "bd":1}
return TkGUI.SeparatorFrame(p, text, fill, height=height, relief=relief, **extras)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment