[Ruby/Tk example] Calendar [incr Widget]

  • Thread starter Morton Goldberg
  • Start date
M

Morton Goldberg

Makes a nice little calendar window. It opnens showing November,
2006. Clicking on any date results in the date being printed to stdout.

<code>
#! /usr/bin/ruby -w
# Author: Morton Goldberg
#
# Date: August 31, 2006
#
# Instant Calendar

require 'tk'
require 'tkextlib/iwidgets'

DEBUG = []

begin
root = TkRoot.new {title 'Ruby/Tk Calendar'}

cal = Tk::Iwidgets::Calendar.new(root) {
outline 'black'
weekdaybackground 'gray90'
weekendbackground 'white'
command {p cal.get}
}
cal.pack('pady'=>10)
cal.show('11/1/2006')

# Set initial window geometry; i.e., size and placement.
win_w, win_h = 250, 195
# root.minsize(win_w, win_h)
win_lf = (root.winfo_screenwidth - win_w) / 2
root.geometry("#{win_w}x#{win_h}+#{win_lf}+50")

# Set resize permissions.
root.resizable(false, false)

# Make Cmnd+Q work as expected.
root.bind('Command-q') {Tk.root.destroy}

Tk.mainloop
ensure
puts DEBUG unless DEBUG.empty?
end
</code>

Regards, Morton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top