Python Forum
[Tkinter] Override the paste function(copy from excel file - paste in separate tkinter entryes)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Override the paste function(copy from excel file - paste in separate tkinter entryes)
#4
(Jun-05-2020, 02:16 AM)deanhystad Wrote:
from tkinter import *
 
def create_table(window, rows, columns):
    table = []
    for r in range(rows):
        row = []
        for c in range(columns):
            var   = StringVar()
            entry = Entry(window, textvar=var)
            entry.grid(row=r, column=c, pady=1, padx=1, ipady=4)
            row.append(var)
        table.append(row)
    return table

def paste(event):
    rows = root.clipboard_get().split('\n')
    for r, row in enumerate(rows):
        values = row.split('\t')
        for c, value in enumerate(values):
            table[r][c].set(value)
 
root = Tk()
root.title("Tolerance changes requests")
root.bind_all("<<Paste>>", paste)
table = create_table(root, 10, 4)
 
root.mainloop()
Now you have to figure out what entry was clicked to get the starting row and column for the paste.

There are probably Tkinter table widgets. Have you looked?

Thank you very much,
Very elegant way to do it and it's a great step ahead for me, I'm stuck here for some time.

I'm away for a few days but I will try to complete the code when I will be back. The clicked entry can be identified as root.focus_get().

About Tkinter widgets, I've tried other ways but this one seems to be the closed to my needs.
Reply


Messages In This Thread
RE: Override the paste function(copy from excel file - paste in separate tkinter entryes) - by AndreiV - Jun-05-2020, 04:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using Tkinter inside function not working Ensaimadeta 5 5,020 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  Tkinter won't run my simple function AthertonH 6 3,829 May-03-2022, 02:33 PM
Last Post: deanhystad
  [Tkinter] tkinter best way to pass parameters to a function Pedroski55 3 4,832 Nov-17-2021, 03:21 AM
Last Post: deanhystad
  Creating a function interrupt button tkinter AnotherSam 2 5,512 Oct-07-2021, 02:56 PM
Last Post: AnotherSam
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 5,004 Oct-01-2021, 05:00 PM
Last Post: Yoriz
  [PyQt] How to Copy-Paste a table from Office apps to QTableView? Vittorio 5 7,225 Aug-05-2021, 11:14 AM
Last Post: Axel_Erfurt
  tkinter get function finndude 2 2,937 Mar-02-2021, 03:53 PM
Last Post: finndude
  tkinter -- after() method and return from function -- (python 3) Nick_tkinter 12 7,389 Feb-20-2021, 10:26 PM
Last Post: Nick_tkinter
  [PyGUI] Python Application Not Finding Excel File dseals26 2 2,842 Feb-17-2021, 01:45 AM
Last Post: thewolf
Bug [PyQt] Qt app won't crash after sys.excepthook override Alfalfa 3 2,658 Dec-28-2020, 01:55 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020