SHARE
TWEET

text editor

a guest Nov 27th, 2011 1,918 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. package require tile
  3. package require Tclx
  4.  
  5. ttk::setTheme default
  6. set filetypes {{"*.txt files" ".txt"}}
  7.  
  8. proc load_file {} {
  9.         set fn [tk_getOpenFile -filetypes $::filetypes]
  10.         if {$fn == ""} return
  11.  
  12.         .text.textbox delete 1.0 end
  13.         .text.textbox insert 1.0 [read_file $fn]
  14. }
  15.    
  16. proc save_file {} {
  17.         set fn [tk_getSaveFile -filetypes $::filetypes]
  18.         if {$fn == ""} return
  19.         if {![string match -nocase "*.txt" $fn]} {
  20.                 set fn "$fn.txt"
  21.         }
  22.  
  23.         write_file $fn [.text.textbox get 1.0 end]
  24. }
  25.    
  26. ttk::frame .panel -height 60
  27. ttk::frame .text -height 340 -width 600
  28.  
  29. pack .panel -side top -fill x
  30. pack .text -side bottom -fill both -expand 1
  31.  
  32. text .text.textbox -font "Arial 14" -wrap word -yscrollcommand { .text.scrollbar set } -bg white -fg black
  33. ttk::scrollbar .text.scrollbar -command { .text.textbox yview }
  34.  
  35. pack .text.textbox -side left -fill both -expand 1
  36. pack .text.scrollbar -side right -fill y
  37.  
  38. ttk::button .panel.load -text Load -command load_file
  39. ttk::button .panel.save -text Save -command save_file
  40. ttk::button .panel.quit -text Quit -command exit
  41.  
  42. pack .panel.load -side left
  43. pack .panel.save -side left
  44. pack .panel.quit -side left
  45.  
  46.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top