Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thought I would share my solution, based on several code snippets on stackoverflow. It includes a minimum application to test:</p> <p>edit: class bindings might not work. Should that be the case use normal bindings and return "break" in the select_all functions.</p> <pre><code>import Tkinter as tk if 1: # nice widgets import ttk else: ttk = tk class EntryPlus(ttk.Entry): def __init__(self, *args, **kwargs): ttk.Entry.__init__(self, *args, **kwargs) _rc_menu_install(self) # overwrite default class binding so we don't need to return "break" self.bind_class("Entry", "&lt;Control-a&gt;", self.event_select_all) self.bind("&lt;Button-3&gt;&lt;ButtonRelease-3&gt;", self.show_menu) def event_select_all(self, *args): self.focus_force() self.selection_range(0, tk.END) def show_menu(self, e): self.tk.call("tk_popup", self.menu, e.x_root, e.y_root) class TextPlus(tk.Text): def __init__(self, *args, **kwargs): tk.Text.__init__(self, *args, **kwargs) _rc_menu_install(self) # overwrite default class binding so we don't need to return "break" self.bind_class("Text", "&lt;Control-a&gt;", self.event_select_all) self.bind("&lt;Button-3&gt;&lt;ButtonRelease-3&gt;", self.show_menu) def event_select_all(self, *args): self.focus_force() self.tag_add("sel","1.0","end") def show_menu(self, e): self.tk.call("tk_popup", self.menu, e.x_root, e.y_root) def _rc_menu_install(w): w.menu = tk.Menu(w, tearoff=0) w.menu.add_command(label="Cut") w.menu.add_command(label="Copy") w.menu.add_command(label="Paste") w.menu.add_separator() w.menu.add_command(label="Select all") w.menu.entryconfigure("Cut", command=lambda: w.focus_force() or w.event_generate("&lt;&lt;Cut&gt;&gt;")) w.menu.entryconfigure("Copy", command=lambda: w.focus_force() or w.event_generate("&lt;&lt;Copy&gt;&gt;")) w.menu.entryconfigure("Paste", command=lambda: w.focus_force() or w.event_generate("&lt;&lt;Paste&gt;&gt;")) w.menu.entryconfigure("Select all", command=w.event_select_all) if __name__ == "__main__": class SampleApp(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.entry = EntryPlus(self) self.text = TextPlus(self) self.entry.pack() self.text.pack() self.entry.insert(0, "copy paste") self.text.insert(tk.INSERT, "copy paste") app = SampleApp() app.mainloop() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload