Advertisement
furas

Python - Tkinter - using frames to group widgets in row

Aug 23rd, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import tkinter as tk
  2.  
  3. root = tk.Tk()
  4.  
  5. main_frame = tk.Frame(root)
  6. main_frame.pack()
  7.  
  8.  
  9. fs = [] # list to keep all frames (but I don't use it in this example)
  10.  
  11.  
  12. for r in range(10): # (r)ow
  13.    
  14.     # create frame to keep labels in row
  15.     f = tk.Frame(main_frame)
  16.     f.grid(row=r)
  17.    
  18.     # keep frame on list to use it later (to move or remove it)
  19.     fs.append( f )
  20.  
  21.     # add some labels in frame in one row
  22.     for c in range(10): #(c)olumn
  23.         t = '| {}.{} |'.format(r, c)
  24.        
  25.         l = tk.Label(f, text=t)
  26.         l.grid(row=0, column=c)
  27.        
  28.     # add button to remove frame
  29.     b = tk.Button(f, text='Delete', command=lambda x=f:x.grid_forget())
  30.     b.grid(row=0, column=10)
  31.  
  32. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement