def __init__(self, master, name, *args, **kwargs): ''' name is used to implement widget memory scrollbars argument can be: both : both always visible x : only horizontal always visible y : only vertical always visible auto : scrollbars shown only when needed none : never shown ''' self._scrollbars = kwargs.pop('scrollbars', None) self.outer_attr = set(dir(tk.Widget)) # a list of attributes that the outer frame should handle self.outer_frame = tk.Frame(master, 'outerframe') self.grid_columnconfigure(1, weight=1) self.grid_rowconfigure(1, weight=1) self.vsb = ttk.Scrollbar(self.outer_frame, orient='vertical') self.hsb = ttk.Scrollbar(self.outer_frame, orient='horizontal') self.vsb.opts = {'column':2, 'row':1, 'sticky':'nesw'} self.hsb.opts = {'column':1, 'row':2, 'sticky':'nesw'} self.canvas = tk.Canvas(self.outer_frame, 'canvas', bd=0, highlightthickness=0, yscrollcommand=self.vsb.set, xscrollcommand=self.hsb.set) self.canvas.grid(column=1, row=1, sticky='nesw') self.vsb.config(command=self.canvas.yview) self.hsb.config(command=self.canvas.xview) self.canvas.xview_moveto(0) self.canvas.yview_moveto(0) self.canvas.bind('<Configure>', self._reconfigure) self.frame = tk.Frame(self.canvas, name) self.frame_id = self.canvas.create_window(0, 0, window=self.frame, anchor='nw') self.frame.bind('<Configure>', self._reconfigure) self.canvas.bind("<Enter>", self._bind_events) self.canvas.bind("<Leave>", self._unbind_events) self._showscrollbars() 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)
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 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: def drop_enter(event):