一个特别短的ruby/tk代码:
require 'tkextlib\iwidgets' require 'tkextlib\bwidget' x = 0 101.times {|i| x+=i} Tk.messageBox(:type=>:ok,:title=>"win",:message=>"total 100 is #{x}")
但是运行提示出错:
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- tkextlib\iwidgets (LoadError) from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require' from 1945.rb:1:in `<main>'
这段代码原来是windows下写的,首先发现路径分隔符在linux需要用/。windows下估计/和\都可以吧?!然后接着运行,原来的错误木有了,新的错误出现鸟:
/usr/lib/ruby/2.1.0/tk/package.rb:86:in `rescue in require': TkPackage can't find package BWidget (RuntimeError) from /usr/lib/ruby/2.1.0/tk/package.rb:83:in `require' from /usr/lib/ruby/2.1.0/tkextlib/bwidget.rb:16:in `<top (required)>' from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require' from 1945.rb:2:in `<main>'
提示找不到BWidget包,遂locate之,发现头文件啥的都是有的啊:
/usr/lib/ruby/2.1.0/tkextlib/bwidget /usr/lib/ruby/2.1.0/tkextlib/bwidget.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/arrowbutton.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/bitmap.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/button.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/buttonbox.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/combobox.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/dialog.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/dragsite.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/dropsite.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/dynamichelp.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/entry.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/label.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/labelentry.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/labelframe.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/listbox.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/mainframe.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/messagedlg.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/notebook.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/pagesmanager.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/panedwindow.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/panelframe.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/passwddlg.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/progressbar.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/progressdlg.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/scrollableframe.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/scrolledwindow.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/scrollview.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/selectcolor.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/selectfont.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/separator.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/setup.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/spinbox.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/statusbar.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/titleframe.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/tree.rb /usr/lib/ruby/2.1.0/tkextlib/bwidget/widget.rb /usr/lib/x86_64-linux-gnu/deja-dup/libwidgets.so /usr/lib/x86_64-linux-gnu/qt5/qml/QtQuick/PrivateWidgets/libwidgetsplugin.so
难道是库文件没有?于是乎用 sudo apt-get install bwidget安装,接着运行,这个世界清净啦: