Guest User

Untitled

a guest
Sep 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk
  3.  
  4.  
  5. class ToggledFrame(tk.Frame):
  6.     def __init__(self, parent, text="", *args, **options):
  7.         tk.Frame.__init__(self, parent, *args, **options)  # 沒有加self會卡住
  8.         # super().__init__(parent, *args, **options)
  9.         self.show = tk.IntVar()
  10.         self.show.set(0)
  11.         # 製作Frame
  12.         self.title_frame = ttk.Frame(self)
  13.         self.title_frame.pack(fill="x", expand=1)  # fill="x", expand=1
  14.  
  15.         # 製作button放在frame
  16.         self.toggle_button = ttk.Checkbutton(self.title_frame,
  17.                                              width=2,
  18.                                              text=text,
  19.                                              command=self.toggle,
  20.                                              variable=self.show,
  21.                                              style='Toolbutton')
  22.  
  23.         self.toggle_button.pack(fill="x", expand=1)  # side="left"
  24.  
  25.         self.sub_frame = tk.Frame(self, relief="sunken",
  26.                                   borderwidth=1)  # sunken  flat raised
  27.  
  28.     def toggle(self):
  29.         if bool(self.show.get()):
  30.             self.sub_frame.pack(fill="x", expand=1)
  31.             # self.toggle_button.configure(text='-')
  32.         else:
  33.             self.sub_frame.forget()
  34.             # self.toggle_button.configure(text='+')
Add Comment
Please, Sign In to add comment