Posted to tcl by iobates at Thu Aug 20 12:52:55 GMT 2026view raw

  1. #!/usr/bin/env tclsh
  2.  
  3. package require Tk
  4. package require sqlite3
  5.  
  6. sqlite3 db /home/devuan/db/zote.db
  7.  
  8. db eval {CREATE TABLE IF NOT EXISTS zotes(note_title text, note_id integer, note_content_part integer, content text)}
  9. db eval {CREATE TABLE IF NOT EXISTS links(prim integer, second integer)}
  10.  
  11. proc every {ms cmd} {
  12. {*}$cmd
  13. after $ms [list after idle [namespace code [info level 0]]]
  14. }
  15.  
  16. wm title . "Zote"
  17. set frm [ttk::frame .f -padding "2 2 5 5"]
  18. grid $frm -column 0 -row 0 -sticky nsew
  19. set quit [ttk::button .f.qbtn -width 1 -text "X" -command {exit}]
  20. grid $quit -column 2 -row 1 -sticky ns
  21. set lbl [ttk::label .f.lbl -text "Welcome to Zotes"]
  22. grid $lbl -column 1 -row 1 -sticky ns
  23.  
  24. set txtfield [text .f.cnvs]
  25. grid $txtfield -column 1 -row 3 -sticky ns
  26.  
  27. set get [ttk::button .f.gbtn -text "Save Text" -command {save}]
  28. grid $get -column 1 -row 4 -sticky ns
  29.  
  30. set charlbl [ttk::label .f.chlbl -textvariable chars]
  31. grid $charlbl -column 2 -row 5 -sticky ns
  32.  
  33. set titlelbl [ttk::entry .f.tintry -textvariable title]
  34. grid $titlelbl -column 1 -row 2 -sticky ns
  35.  
  36. proc save {} {
  37. set txt ""
  38. puts $::title
  39. set txt [$::txtfield get 1.0 end]
  40. puts [tags]
  41. }
  42.  
  43. proc tags {} {
  44. set start [$::txtfield search -regexp -all {!} 0.0]
  45. global name
  46. puts [llength $start]
  47. for {set i 0} {$i < [llength $start]} {incr i} {
  48. set end [regexp {!([a-zA-Z]+)} [$::txtfield get [lindex $start $i] end] m word]
  49. set length [string length $word]
  50. set name $word
  51. set end_pos [expr [lindex $start $i] + 0.$length + 0.1]
  52. $::txtfield tag add link$word [lindex $start $i] $end_pos
  53. $::txtfield tag bind link$word <1> {set name [$::txtfield tag cget link$name get] puts $name}
  54. }
  55. }
  56.  
  57.  
  58.  
  59. proc characters {} {
  60. set words [$::txtfield get 0.0 end]
  61. set ::chars [expr [string length $words] - 1]
  62. }
  63.  
  64. every 100 characters
  65.  

Comments

Posted by schelte at Thu Aug 20 13:15:32 GMT 2026 [text] [code]

Change line 53 to: $::txtfield tag bind link$word <1> [list printlink %W link$name] Then create a proc printlink {t link} {puts [$t tag cget $link get]}

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week