Die Programmiersprache Ruby

Blog| Forum| Wiki  

Text-Editor mit Ruby-Tk

Ein einfacher Text-Editor mit Ruby-Tk, den man leicht erweitern kann. Er enthält ein Textfeld, 2 Scrollbars und ein einfaches Menu. Hier das ganze auch als FoxEditor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby

require 'tk'

root = TkRoot.new

bar = TkMenu.new()
file = TkMenu.new(bar)
file.add('command','label'=>'Quit', 'command'=>proc{root.destroy})
bar.add('cascade','menu'=>file,'label'=>'Datei')
root.menu(bar)        

frame = TkFrame.new(root).pack('side'=>'top','expand'=>1,'fill'=>'both')

yscr = TkScrollbar.new(frame).pack('side'=>'right','fill'=>'y')
xscr = TkScrollbar.new(frame,'orient'=>'hor').pack('side'=>'bottom','fill'=>'x')

text = TkText.new(frame) {
    wrap 'none'
    pack
}

yscr.command(proc{|*args|
    text.yview(*args)
})
xscr.command(proc{|*args|
    text.xview(*args)
})

text.yscrollcommand(proc{|first, last|
    yscr.set(first,last)
})
text.xscrollcommand(proc{|first, last|
    xscr.set(first,last)
})
        
TkButton.new(root) {
    text "Exit"
    command proc{exit}
    pack
}

Tk.mainloop