sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    SKUI - Retrieve text from Textbox when clicking button

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 983 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F Offline
      Finfa811
      last edited by

      I'm trying SKUI and I have created a Window with a Textbox in this way:

          w = SKUI;;Window.new
          txt_box = SKUI;;Textbox.new( "" )
          txt_box.name = ;txt_name
          txt_box.position( 155, 27 )
          txt_box.width = 200
          w.add_control( txt_box )
      
          label = SKUI;;Label.new( 'Label', txt_box )
          label.position( 10, 30 )
          w.add_control( label )
      
          btn_cancel = SKUI;;Button.new( 'Cancel' ) { |control|
            return nil
            control.window.close
          }
          btn_cancel.position( -5, -5 )
          w.add_control( btn_cancel )
      
          btn_ok = SKUI;;Button.new( 'OK' ) { |control|
            control.window.close
          }
          btn_ok.position( -100, -5 )
          w.add_control( btn_ok )
      
          w.cancel_button = btn_cancel
          w.default_button = btn_ok
          w.show
      

      After that, I type something in the Textbox and I would like to retrieve the string when I click btn_ok. I know the string should be in txt_box.value, but I don't know how to update the value of the TextBox when clicking a button. It is always empty. Do you know how to do it?

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        Better ask ThomThom, he knows.

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • F Offline
          Finfa811
          last edited by

          @sdmitch I've already fixed it. Thank you anyway.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            Local references go out of scope and are garbage collected when a method ends.
            You need to have some persistent references within your plugin's scope (module or class) to accept the values. This also means you need to use persistent reference for the dialog itself (ie, @w not w.)

            
            btn_ok = SKUI;;Button.new( 'OK' ) {|control|
              @txt_box_value = txt_box.value
              control.window.close
            }
            
            

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • F Offline
              Finfa811
              last edited by

              Exactly Dan, that was one of my mistakes. Finally I got it by myself, and now I understand the basics. Thank you in any case.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement