[wxruby-users] Map Tk to WxRuby
Alex Fenton
alex at pressure.to
Mon Jul 27 08:39:17 EDT 2009
Quan Nguyen wrote:
> I try to map a Tk to Wx for the simple animation example below. The code
> for Wx is way too long. Can anyone help me to come up with the shorter
> code for wx? Either in WxRuby or WxPython would be fine. Wonder is there
> a script out there (or an easier or convenient way) to map Tk script to
> Wx script for both WxPython and WxRuby?
I wouldn't be surprised if the Wx version were a bit longer. Wx offers
more flexibility at the expense of making simple things a bit longer -
for simplistic apps, Tk, or Shoes, are often better choices.
It would be useful to define what the script is expected to do so that a
proper comparison could be made - for example, is the timing of the
animation specified, b/c I can't see how this is done in the Python/Tk
version.
Anyway the version below does the same as your version in < 50% of the
code. If I jammed lots of things onto one line, like the Tk/Ruby version
it could be shorter...
hth
alex
__
require 'wx'
include Wx
App.run do
frame = Frame.new(nil, :title => 'Sun Rising', :size => [300, 300])
canvas = Panel.new(frame)
canvas.background_colour = WHITE
frame.show
i = 0
Timer.every(100) do
canvas.paint do | dc |
dc.clear
dc.brush = RED_BRUSH
dc.draw_circle(i * 2, i * 2, i)
end
i += 1
exit if i == 100
end
end
More information about the wxruby-users
mailing list