'I am writing a GUI application in tkinter, I have multiple entry widgets, and I am trying to assign a menu with copy and paste option, I am having trouble with paste function. To paste the text from clipboard I need to know the current cursor location based on which entry widget the cursor is, and I am not able to get the current cursor location.'
import tkinter as tk
def do_popup(event):
right_click_menu.tk_popup(event.x_root, event.y_root)
def copy_clipboard():
global selected
root.clipboard_clear()
if path_for_result.select_present():
selected = selected_text.selection_get()
root.clipboard_append(selected)
elif user_defined_loadcases.select_present():
selected = selected_text.selection_get()
root.clipboard_append(selected)
def paste_clipboard():
global selected
if root.clipboard_get():
path_for_result.insert(tk.INSERT,root.clipboard_get())
user_defined_loadcases.insert(tk.INSERT,root.clipboard_get())
right_click_menu = tk.Menu(frame, tearoff =0)
right_click_menu.add_command(label ="Cut")
right_click_menu.add_command(label ="Copy",command = copy_clipboard)
right_click_menu.add_command(label ="Paste",command = paste_clipboard)
path_for_result.bind("<Button-3>", do_popup)
user_defined_loadcases.bind("<Button-3>", do_popup)