Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get the value of the Entry? #72

Closed
QuintinTao opened this issue Jan 10, 2022 · 3 comments
Closed

How can I get the value of the Entry? #72

QuintinTao opened this issue Jan 10, 2022 · 3 comments

Comments

@QuintinTao
Copy link

QuintinTao commented Jan 10, 2022

I want to get the user_name and passwords' values when I click the btn submit.

                 append = &gtk::Entry {
                        //set_buffer: &model.entry,
                        set_tooltip_text: Some("username"),
                        connect_activate(sender) => move |_| {
                            //send!(sender, AppMsg::get_user_name);
                        },
                    },
                 },

I want to get the Entry value when I click the sumit btn.

             append = &gtk::Box {
                    set_orientation: gtk::Orientation::Horizontal,
                    set_spacing: 10,
                    append = &gtk::Button {
                        set_label: "login",
                        connect_clicked(sender) => move |_| {
                           // **how can I get the Entry value here?**
                            send!(sender, AppMsg::Login((model.user_name, model.password)));
                        },
                    },
                    append = &gtk::Button {
                        set_label: "reg",
                        connect_clicked(sender) => move |_| {
                            send!(sender, AppMsg::Reg);
                        },
                    },
                },
@AaronErhardt
Copy link
Member

There are two options:

  1. You store the value of the entry in your model. The easiest way to do this is to create an EntryBuffer and store it inside the model. Then you use set_buffer to set the buffer of the entry in the view! macro. Whenever you want to get the value of the entry you can the just call self.buffer_name.text() in the update method.

  2. You name your entries and move them into the button closure:

connect_clicked(sender, entry1_name, entry2_name) => move |_| {
   let user_name = entry1_name.buffer().text();
   let password = entry2_name.buffer().text();
   send!(sender, AppMsg::Login((user_name, password)));
},

I hope this helps you :)

@QuintinTao
Copy link
Author

it does help me!thanks
By the way how can I learn relm? I need some doc to learn API .

There are two options:

  1. You store the value of the entry in your model. The easiest way to do this is to create an EntryBuffer and store it inside the model. Then you use set_buffer to set the buffer of the entry in the view! macro. Whenever you want to get the value of the entry you can the just call self.buffer_name.text() in the update method.
  2. You name your entries and move them into the button closure:
connect_clicked(sender, entry1_name, entry2_name) => move |_| {
   let user_name = entry1_name.buffer().text();
   let password = entry2_name.buffer().text();
   send!(sender, AppMsg::Login((user_name, password)));
},

I hope this helps you :)

It does help me. Thanks .by the way where can I learn relm.I mean the api.

@AaronErhardt
Copy link
Member

You can learn Relm4 with the book, the examples or the documentation. You can find all those links in the Readme.
Also, this article might help you: https://aaronerhardt.github.io/blog/posts/gui_speedrun/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants