Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. from thonny import get_workbench, get_shell
  2. import tkinter as tk
  3. from tkinter import ttk
  4.  
  5. class PostItView(ttk.Frame):
  6. def __init__(self, master):
  7. ttk.Frame.__init__(self, master)
  8. self.ent1 = tk.Entry(self)
  9. self.ent1.pack()
  10. self.ent2 = tk.Entry(self)
  11. self.ent2.pack()
  12.  
  13.  
  14. tk.Button(self, text='按鈕', command=self.do).pack()
  15.  
  16.  
  17. def do(self):
  18. #shell = get_shell()
  19. #shell.submit_python_code(self.ent.get()+ '\n')
  20. #shell.focus_set()
  21. editor = get_workbench().get_editor_notebook().get_current_editor()
  22. text = editor.get_text_widget()
  23.  
  24. text.focus()
  25.  
  26.  
  27.  
  28. #not work -- text.event_generate("<Double-1>")
  29. # double click emulation
  30. #x = 0
  31. #y = 100
  32. print(text.index('insert'))
  33. (x, y ,_ , _) = text.bbox('insert')
  34. for i in range(2):
  35. text.event_generate('<Button-1>', x=x, y=y)
  36. text.event_generate('<ButtonRelease-1>', x=x, y=y)
  37.  
  38. #print(text.tag_ranges('sel'))
  39.  
  40. #text.mark_set('insert', 'insert-2chars')
  41.  
  42. #print(text.get('insert-1chars','insert+1chars'))
  43.  
  44. #text.tag_remove("sel", "1.0", "end")
  45. #text.tag_add("sel", "insert wordstart", "insert wordend")
  46. #for i in text.tag_ranges('sel'):
  47. # print(text.index(i))
  48. #print()
  49. #ind = text.index('insert')
  50. #print(ind)
  51. #print(type(ind))
  52.  
  53. #text.direct_delete(tk.SEL_FIRST, tk.SEL_LAST)
  54. #text.direct_insert("insert wordend", self.ent2.get())
  55.  
  56. def load_plugin():
  57. get_workbench().add_view(PostItView, '便利貼', 'nw')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement