Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

python - How to know current cursor location out of multiple Entry widgets in tkinter

'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)
question from:https://stackoverflow.com/questions/65840070/how-to-know-current-cursor-location-out-of-multiple-entry-widgets-in-tkinter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...