Guest User

Untitled

a guest
Apr 18th, 2019
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import tkinter as tk
  2.  
  3.  
  4. class Container(tk.Frame):
  5. def __init__(self, parent = None, priority = 3, bg = 'bisque'):
  6. self.inpList = []
  7. tk.Frame.__init__(self, parent)
  8.  
  9. self.can = tk.Canvas(window, bg = 'aqua')
  10. self.f = tk.Frame(self.can, bg = bg, height = 200, width = 300)
  11. self.f.pack(in_ = self.can, fill = 'both', expand = True)
  12. self.f.propagate(False)
  13. self.b = tk.Button(self.f, text = 'add', command = lambda: self.add_task(priority))
  14. self.scb = tk.Scrollbar(self.can)
  15.  
  16. self.can.create_window(4, 4, window = self.f)
  17. self.f.bind("<Configure>", self.on_frame)
  18. self.can.configure(yscrollcommand = self.scb.set)
  19. self.scb.configure(command = self.can.yview)
  20.  
  21. self.scb.pack(side = 'right', fill = 'y')
  22. self.can.pack(fill = 'both', expand = True)
  23. self.b.pack(side = 'left', anchor = 's')
  24.  
  25. self.s = tk.Button(self.f, text = 'print all', command = self.print_all)
  26. self.s.pack(side = 'left')
  27.  
  28. self.t = None
  29. self.saveBtn = None
  30.  
  31. def on_frame(self, event):
  32. self.can.configure(scrollregion = self.can.bbox('all'))
  33.  
  34. def add_task(self, priority): # refer 1.2_text for implementation
  35. finished = False
  36. self.t = tk.Text(self.f)
  37. self.t.configure(height = 10, wrap = 'word')
  38. self.t.bind("<Return>", self.save_task)
  39. self.t.pack(fill = tk.X)
  40.  
  41. def print_all(self):
  42. print(self.inpList)
  43.  
  44. def save_task(self, event):
  45. td = self.t.get('current linestart', 'current lineend') # 1.0 end-1c
  46. self.inpList.append(td)
  47.  
  48. def to_json(self):
  49. pass
  50.  
  51.  
  52. if __name__ == '__main__':
  53. window = tk.Tk()
  54. window.minsize(300, 600)
  55.  
  56. p1 = Container(window, priority = 1)
  57. p2 = Container(window, bg = 'blue', priority = 2)
  58. p3 = Container(window, bg = 'red', priority = 3)
  59.  
  60. window.mainloop()
Add Comment
Please, Sign In to add comment