Advertisement
ALEXANDAR_GEORGIEV

treeview_opiti

Jul 31st, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import ttk
  3.  
  4. import textwrap
  5.  
  6.  
  7. def wrap(string, lenght=8):
  8.     return '\n'.join(textwrap.wrap(string, lenght))
  9.  
  10.  
  11. myApp = Tk()
  12.  
  13. NewTree = ttk.Treeview(myApp, height=5)
  14. NewTree['show'] = 'headings'
  15. s = ttk.Style()
  16. s.configure('Treeview', rowheight=20)
  17.  
  18. NewTree["columns"] = ("1", "2")
  19.  
  20. NewTree.column("1", width=60)
  21. NewTree.column("2", width=60)
  22.  
  23. NewTree.heading("1", text="col a")
  24. NewTree.heading("2", text="col b")
  25.  
  26. item = NewTree.insert("", "end", values=(wrap("i want to wrap this text"),
  27.                                          wrap("and this text")))
  28.  
  29. NewTree.grid(row=0, column=0)
  30.  
  31. myApp.mainloop()
  32. #---------------------------------------------------------------
  33. from tkinter import *
  34. from tkinter import ttk
  35. import textwrap
  36.  
  37. def wrap(string, lenght=20):
  38.     return '\n'.join(textwrap.wrap(string, lenght))
  39.  
  40.  
  41. ws = Tk()
  42. ws.title("PythonGuides")
  43.  
  44. tv = ttk.Treeview(ws, columns=(1, 2, 3), show='headings', height=8)
  45. tv.pack()
  46.  
  47. tv.heading(1, text="name")
  48. tv.heading(2, text="eid")
  49. tv.heading(3, text="Salary")
  50.  
  51. def update_item():
  52.     selected = tv.focus()
  53.     temp = tv.item(selected, 'values')
  54.     sal_up = float(temp[2]) + float(temp[2]) * 0.05
  55.     tv.item(selected, values=(temp[0], temp[1], sal_up))
  56.  
  57. tv.insert(parent='', index=0, iid=0, values=(wrap("vineet hkjhk ljljoi vgvgvy daaaa Aleksandyr georgiev Georgiew"), "e11", 1000000.00))
  58. tv.insert(parent='', index=1, iid=1, values=("anil", "e12", 120000.00))
  59. tv.insert(parent='', index=2, iid=2, values=("ankit", "e13", 41000.00))
  60. tv.insert(parent='', index=3, iid=3, values=("Shanti", "e14", 22000.00))
  61.  
  62. Button(ws, text='Increment Salary', command=update_item).pack()
  63.  
  64. style = ttk.Style()
  65. style.theme_use("default")
  66. style.map("Treeview")
  67.  
  68. ws.mainloop()
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement