Advertisement
here2share

# Tk_DeleteChkdRows.py

Oct 8th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. # Tk_DeleteChkdRows.py
  2. from Tkinter import *
  3.  
  4. i=2
  5. rows = []
  6.  
  7. def add_row():
  8.     global i
  9.     i=i+1
  10.     items = []
  11.     var = IntVar()
  12.     c = Checkbutton(root, variable = var)
  13.     c.val = var
  14.     items.append(c)
  15.     c.grid(row = i, column = 0)
  16.     for j in range(1,5): #Columns
  17.         b = Entry(root)
  18.         items.append(b)
  19.         b.grid(row=i, column=j)
  20.     rows.append(items)
  21.  
  22. def delete_row():
  23.     for rowno, row in reversed(list(enumerate(rows))):
  24.         if row[0].val.get() == 1:
  25.             for i in row:
  26.                 i.destroy()
  27.             rows.pop(rowno)
  28.  
  29.  
  30. root = Tk()
  31. bt = Button(root , text = 'Add Row', command = add_row)
  32. bt.grid(row =0, column=0)
  33.  
  34.  
  35. dl = Button(root , text = 'Delete Row', command = delete_row)
  36. dl.grid(row =0, column=1)
  37.  
  38. v0 = StringVar()
  39. e0 = Entry(root, textvariable = v0)
  40. v0.set('Select')
  41. e0.grid(row = 1, column = 0 )
  42.  
  43. v1 = StringVar()
  44. e1 = Entry(root, textvariable = v1)
  45. v1.set('Col1')
  46. e1.grid(row = 1, column = 1 )
  47.  
  48. v2 = StringVar()
  49. e2 = Entry(root, textvariable = v2)
  50. v2.set('Col2')
  51. e2.grid(row = 1, column = 2)
  52.  
  53. v3 = StringVar()
  54. e3 = Entry(root, textvariable = v3)
  55. v3.set('Col3')
  56. e3.grid(row = 1, column = 3 )
  57.  
  58. v4 = StringVar()
  59. e4 = Entry(root, textvariable = v4)
  60. v4.set('Col4')
  61. e4.grid(row = 1, column = 4 )
  62.  
  63. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement