Ave populus
ho questo codice:
ma quando lo eseguo dà questo errore:codice:require 'gtk2' Gtk.init class Operazioni add = Proc.new do n1 = (n1.get_text).to_i n2 = (n2.get_text).to_i label.set_text("Il risultato e': " + (n1+n2).to_s) end sub = Proc.new do n1 = (n1.get_text).to_i n2 = (n2.get_text).to_i label.set_text("Il risultato e': " + (n1-n2).to_s) end mlt = Proc.new do n1 = (n1.get_text).to_i n2 = (n2.get_text).to_i label.set_text("Il risultato e': " + (n1*n2).to_s) end div = Proc.new do n1 = (n1.get_text).to_i n2 = (n2.get_text).to_i if n2 != 0 label.set_text("Il risultato e': " + (n1/n2).to_s) else label.set_text("Errore di divisione per zero") end end end @box = Gtk::VBox.new(false, 5) title = Gtk::Label.new("") title.set_markup("Scegli l'operazione:\n1) + 2) - \n3) * 4) / ") txt = Gtk::Entry.new() n1 = Gtk::Entry.new() n2 = Gtk::Entry.new() button = Gtk::Button.new(Gtk::Stock::OK) label = Gtk::Label.new("") button.signal_connect("clicked") { str = txt.get_text() if str == '1' add.call elsif str == '2' sub.call elsif str == '3' mlt.call elsif str == '4' div.call else label.set_text("Hai immesso un carattere non valido o non riconosciuto.") end } @box << title << txt << n1 << n2 << button << label window = Gtk::Window.new window.signal_connect("delete_event") { puts "delete event occurred" false } window.signal_connect("destroy") { puts "destroy event occurred" Gtk.main_quit } window.border_width = 10 window.add(@box) window.show_all Gtk.main
che può essered:/gui.rb:64: undefined method `get_text' for <Gtk::Entry:02A737C0 ptr=0305076
0> (NoMethodError)
from d:/toki.rb:63:in `call'
from d:/toki.rb:95:in `main'
from d:/toki.rb:95
tra l'altro se nell'evento clicked del button non metto alcun codica, funziona perfettamente.

Rispondi quotando