我正在尝试在gtk中创建一个窗口。这是我的代码:
require 'gtk3'
class Win < Gtk::Window
include Gtk
def initialize
super
set_title "RubyCalculator"
set_default_geometry 300 , 300
#show show works here fine
end
end
Win.new
Win.show # I get error here
Gtk.main
我无法访问类外的继承方法。这是错误:
Traceback (most recent call last):
./Main.rb:19:in `<main>': undefined method `show' for Win:Class (NoMethodError)
答案 0 :(得分:2)
window = Win.new
window.show
您应该在您创建的实例上调用show方法。不在班级本身