Advertisement
furas

Python - lines in grid

May 28th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. ##################################################################
  2. # using: padx=(1,0), pady=(1,0)
  3. ##################################################################
  4.  
  5. import tkinter as tk
  6.  
  7. root = tk.Tk()
  8. root['bg'] = 'black'
  9.  
  10. for c in range(10):
  11.     for r in range(10):
  12.         txt = "({},{})".format(r,c)
  13.         l = tk.Label(root, text=txt)
  14.         #l.grid(row=r, column=c, padx=(1,0), pady=(1,0))
  15.  
  16.         # skip external lines
  17.         px = (1,0) if c > 0 else (0,0)
  18.         py = (1,0) if r > 0 else (0,0)
  19.         l.grid(row=r, column=c, padx=px, pady=py)
  20.  
  21. root.mainloop()
  22.  
  23. ##################################################################
  24. # using: borderwidth=1, relief="solid"
  25. # (internal lines have size 2px, external lines have size 1px)
  26. ##################################################################
  27.  
  28. import tkinter as tk
  29.  
  30. root = tk.Tk()
  31. root['bg'] = 'black'
  32.  
  33. for c in range(10):
  34.     for r in range(10):
  35.         txt = "({},{})".format(r,c)
  36.         l = tk.Label(root, text=txt, borderwidth=1, relief="solid")
  37.         l.grid(row=r, column=c)
  38.  
  39. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement