Shurikan117
Shurikan117

Reputation: 105

Save or copy text in Edit_box or line to an external file in Ruby Shoes

Using Shoes 3.3.7

How do I go about grabbing the text typed in an Edit_box and saving it to a file on a button click?

This is what i used. It created the file but it just stays empty...

Shoes.app do
  Stack do
    flow do
      new_box = edit_box "placeholdertext"
    end

    flow do
      button "Save" do
        note_save = ask_save_file
        File.open("#{note_save}", "a") do |copy|
          copy.para "#{new_box.text}"
        end
      end
    end
  end
end

Edit : setting code to,

copy.write(new_box.text)

Still creates a file with empty content

I'm pretty new to all this. Any help is appreciated 😊

Upvotes: 0

Views: 56

Answers (1)

Sebastjan Hribar
Sebastjan Hribar

Reputation: 396

you have to use instance variables in such cases:

Shoes.app do
  stack do
    flow do
      @new_box = edit_box "placeholdertext"
    end

    flow do
      button "Save" do
        note_save = ask_save_file
        File.open("#{note_save}", "w") do |file|
          file.write @new_box.text
        end
      end
    end
  end
end

Best, seba

Upvotes: 0

Related Questions