Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make menubar cut/copy/paste with Python/Tkinter
    primarykey
    data
    text
    <p>I'd like to make menu items (in the menubar, not in a right click pop-up window) that can cut/copy/paste whatever text is selected.</p> <p><em>The equivalent keyboard commands already work without my having done anything to enable them</em>. For example, I can enter text in an entry box, cut it with Control-X, and paste it back (or elsewhere) with Control-C.</p> <p>The posts on the topic I've seen boil down to cut/copy/paste for individual widgets, but that already works. How do I make the menu items activate them?</p> <p>Thanks.</p> <p>EDIT: Just to be clear, The issues are:</p> <ul> <li>how to make the menu items for cut/copy act on whatever text is selected in any widget </li> <li>how to have the paste menu item paste text wherever the text cursor is</li> </ul> <p>Again, the key commands to do this (Control-x, Control-c, Control-v) already work without my having done anything. <em>I know how to make the menus</em>; the question is just what command I should attach to the menu items to have the desired effect.</p> <p>EDIT 2: Ok, I've got a way that works. Since the key commands already work, we can just generate them. In my case, everything is a a notebook named noteBook so </p> <p><code>lambda: self.noteBook.event_generate('&lt;Control-x&gt;')</code></p> <p>cuts as desired. For example:</p> <p><code>editmenu.add_command(label="Cut", accelerator="Ctrl+X", command=lambda: self.noteBook.event_generate('&lt;Control-x&gt;'))</code></p> <p>In use: <a href="https://github.com/lnmaurer/qubit-control-interface/commit/c08c10a7fbc4a637c1e08358fb9a8593dfdf116e" rel="noreferrer">https://github.com/lnmaurer/qubit-control-interface/commit/c08c10a7fbc4a637c1e08358fb9a8593dfdf116e</a></p> <p><strong>Still, there's probably a cleaner way to do this; please reply if you know it.</strong></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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