1

I have created gui for entry using tkinter in tabular form.

This is the simplified version.

In this gui, I have used labels, Entry and Optionmenu. I can load and enter my data easily. But the problem is that there are hundreds of such records. Due to which (I think) tkinter gui takes time to load and lags while scrolling & entering data.

So, I used tkinter Treeview to load my large data which it loads and shows comfortably. enter image description here

But I want to make changes in any desired row of my record which I could achieve by adding entry and optionmenu widgets in treeview if I were able to.

How can I add entry and optionmenu widgets in Amount and Paid(Y/N) column respectively ?

Here is the simplified code for the gui ::

import tkinter as tk
import tkinter.ttk  as ttk


def DesiredTableInTreeView():
    ewindow = tk.Toplevel(window)
    ewindow.title("Desired Table in Treeview Form ")
    ewindow.geometry("250x250+450+150") # Width x Height
    
    PaidStatus=['Y', 'N']
    for i in range(len(EntryData)):
        data=EntryData[i]
         
        sno = ttk.Label(ewindow, text = str(i+1), width=4).grid(row=i,column=0) 
        ids = ttk.Label(ewindow, text = data[1], width=8).grid(row=i,column=1) 
        name = ttk.Label(ewindow, text = data[2], width=12).grid(row=i,column=2) 
        
        amountEntry = tk.Entry(ewindow, width=6 )    
        amountEntry.insert(tk.END, data[3])
        amountEntry.grid(row=i,column=3)
        
        PaidVar = tk.StringVar()
        Paid = ttk.OptionMenu(ewindow, PaidVar, data[4] , *PaidStatus)
        Paid.grid(row=i,column=4)


window = tk.Tk()
window.title("Enter Data ")
window.geometry("250x200+150+150") # Width x Height


Heading = [ 'SNo.', 'Id' ,'Name', 'Amount', 'Paid(Y/N)']

EntryData = [  (1 , 23563, 'Arial' , 5000, 'Y' ),
               (2 , 23570, 'John' ,  15000, 'N' ),
               (3 , 23571, 'Ava' ,  300, 'Y' ),
               (4 , 23573, 'Eric' , 6000, 'N' ),
               (5 , 23575, 'Ross' , 5000, 'Y' ),
               (6 , 23576, 'Jack' ,  350, 'Y' ),
               (7 , 23577, 'Bill' ,  1000, 'N' ),
               (8 , 23580, 'Rob' ,  6050, 'Y' )
             ]

tv = ttk.Treeview(window, show='headings', columns=tuple([str(i) for i in range(1,6)]) ) # , selectmode='extended'
tv.pack(side=tk.LEFT,fill='both', expand='yes')

for i in range(len(Heading)):
     tv.heading(str(i+1), text=Heading[i])
     tv.column(str(i+1), width=45, stretch=tk.NO)   

for i in range(len(EntryData)):
     tv.insert("", 'end', values=EntryData[i] )


DesiredTableInTreeView()


window.mainloop()
jonny789
  • 323
  • 1
  • 8
  • 16
  • I have tried to do this in the past without success. The work around I developed was a new window that opened when you double click on a specific row. The new window has the correct dropdowns, editable fields etc and the user entry is then saved to treeview again. – scotty3785 Dec 16 '20 at 13:15

1 Answers1

0

I Have wanted to do the same thing it seems impossible i even thought of switching to Qt because of this Untill i came by this video

https://www.youtube.com/watch?v=n5gItcGgIkk

  • 2
    A link only answer is not a good answer because the link may be broken/removed in the future. – acw1668 Jul 13 '22 at 00:49
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 13 '22 at 12:13