def __init__(self, master, name, cnf={}, **kw): ''' provide a name to save between script runs. ''' self.outer_attr = set( dir(tk.Widget )) # a list of attributes that the outer frame should handle self.outer = tk.LabelFrame(master, name, cnf) self.settings = self.outer.settings self.outer.bind('<Button-1>', self._toggle) self.inner = tk.Frame(self.outer, name='inner') self.placeholder = tk.Label(self.outer) self.text = '' for attr in [ 'grid_columnconfigure', 'grid_rowconfigure', 'winfo_reqwidth', 'winfo_reqheight', 'configure', 'settings' ]: # only remove these once all widgets are set up self.outer_attr.discard(attr) self.config(**kw) if not hasattr(self.settings, 'collapsed'): self.settings.collapsed = False self._show_hide()
def __init__(self): tk.SoftwarePrefix = True tk.VendorPrefix = 'James Kent' tk.Tk.__init__(self, tk.HKCU, None, 'explorer-selection-logger') self.title('Explorer Selection and path logger') self.protocol("WM_DELETE_WINDOW", self.exit_handler) self.grid_columnconfigure(2, weight=1) self.grid_rowconfigure(2, weight=1) self.pw = ttk.PanedWindow(self, 'pane', orient=tk.HORIZONTAL) self.pw.grid(column=1, row=2, columnspan=2, sticky='nesw') tk.Label(self, text='Path:').grid(column=1, row=1, sticky='nesw') self.path = tk.Entry(self) self.path.grid(column=2, row=1, sticky='nesw') f = tk.Frame(self.pw, 'files') f.grid_columnconfigure(1, weight=1) f.grid_rowconfigure(2, weight=1) tk.Label(f, text='Files:').grid(column=1, row=1, sticky='nesw') self.files = tk.Listbox(f, selectmode=tk.MULTIPLE) self.files.grid(column=1, row=2, sticky='nesw') vsb = ttk.Scrollbar(f, command=self.files.yview) vsb.grid(column=2, row=2, sticky='nesw') self.files.configure(yscrollcommand=vsb.set) self.fmenu = tk.Menu(self, tearoff=False) self.fmenu.add_command(label='Copy', command=self.copy_files) self.files.bind('<Button-3>', self.popup) self.pw.add(f) f = tk.Frame(self.pw, 'selected') f.grid_columnconfigure(1, weight=1) f.grid_rowconfigure(2, weight=1) tk.Label(f, text='Selected:').grid(column=1, row=1, sticky='nesw') self.selected = tk.Listbox(f, selectmode=tk.MULTIPLE) self.selected.grid(column=1, row=2, sticky='nesw') vsb = ttk.Scrollbar(f, command=self.selected.yview) vsb.grid(column=2, row=2, sticky='nesw') self.selected.configure(yscrollcommand=vsb.set) self.smenu = tk.Menu(self, tearoff=False) self.smenu.add_command(label='Copy', command=self.copy_selected) self.selected.bind('<Button-3>', self.popup) self.pw.add(f) f = tk.Frame(self.pw, 'withpath') f.grid_columnconfigure(1, weight=1) f.grid_rowconfigure(2, weight=1) tk.Label(f, text='Selected with path:').grid(column=1, row=1, sticky='nesw') self.selectedpaths = tk.Listbox(f, selectmode=tk.MULTIPLE) self.selectedpaths.grid(column=1, row=2, sticky='nesw') vsb = ttk.Scrollbar(f, command=self.selectedpaths.yview) vsb.grid(column=2, row=2, sticky='nesw') self.selectedpaths.configure(yscrollcommand=vsb.set) self.spmenu = tk.Menu(self, tearoff=False) self.spmenu.add_command(label='Copy', command=self.copy_selectedpaths) self.selectedpaths.bind('<Button-3>', self.popup) self.pw.add(f) ttk.Button(self, text='Copy All', command=self.copy_all).grid(column=1, row=4, columnspan=2, sticky='nesw') self.hwnd = 0 t = Thread(target=self.msgloop) t.daemon = True t.start()
import memtkinter as tk from memtkinter.megawidgets import CollapsibleScrolledFrame if __name__ == '__main__': root = tk.Tk(keytype=tk.HKCU, filepath=None, name='Software\\CollapsibleFrametest') cf = CollapsibleScrolledFrame(root, 'cf', text="Test Frame") cf.pack() for i in range(0, 10): tk.Label(cf, text='test %i' % i).grid(column=1, row=i, sticky='nesw') root.mainloop()
import memtkinter as tk from memtkinter.megawidgets import Grip if __name__ == '__main__': root = tk.Tk(keytype=tk.HKCU, filepath=None, name='Software\\griptest') # this could be any type of widget as long as it has a non zero size # i.e. it can be clicked on. griplabel = tk.Label(root, text='click and drag to move') griplabel.pack() grip = Grip(griplabel) root.mainloop()
#!python3 import memtkinter as tk from tkinter.scrolledtext import ScrolledText from memtkinter import tkdnd root = tk.Tk(keytype=tk.HKCU, filepath=None, name='Software/James Kent/tkdndtest') root.withdraw() root.title('TkinterDnD simple text demo') root.grid_rowconfigure(1, weight=1, minsize=250) root.grid_columnconfigure(0, weight=1, minsize=300) tk.Label(root, text='Drag and drop text here:').grid( row=0, column=0, padx=10, pady=5) buttonbox = tk.Frame(root, 'buttonbox') buttonbox.grid(row=2, column=0, columnspan=2, pady=5) tk.Button(buttonbox, text='Quit', command=root.quit).pack( side=tk.LEFT, padx=5) msg = "You can drop text onto the Label to append it to the Label's text "+\ "string.\nYou can drag the Label's text string into other " +\ "applications.\n" label = tk.Label(root, name='dnd_demo_label', bg='white', relief='sunken', bd=1, highlightthickness=1, text=msg, takefocus=True, justify='left', anchor='nw', padx=5, pady=5) label.grid(row=1, column=0, padx=5, pady=5, sticky='news') # make the Label a drop target: