summaryrefslogtreecommitdiff
path: root/jni/ruby/ext/tk/sample/tkextlib/tcllib/datefield.rb
blob: 3550af7d23a4f8f249b270be96aba14b0daa796d (plain)
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
#!/usr/bin/ruby

require 'tk'
require 'tkextlib/tcllib/datefield'
require 'parsedate'

Tk.root.title('Datefield example')


my_date1 = TkVariable.new
my_date2 = TkVariable.new
my_date1.trace('w'){
  begin
    t = Time.local(*(ParseDate.parsedate(my_date1.value)))
    my_date2.value = t.strftime('%A')
  rescue
    # ignore error
  end
}

df = Tk::Tcllib::Datefield.new(:textvariable=>my_date1)
Tk.grid(TkLabel.new(:text=>'Enter a date:', :anchor=>:e), df, :sticky=>:ew)
Tk.grid(TkLabel.new(:text=>'That date ia a:', :anchor=>:e),
        TkLabel.new(:textvariable=>my_date2, :relief=>:sunken, :width=>12),
        :sticky=>:ew)

df.set_focus

Tk.mainloop