Start a new topic

Cannot set text on a different page

Hello,


I want to set a test (Title od the project) an every page.


I did not understand the use for globale vscope, yet. :(

I defined a text component on each page with different names.

p01title, p02title, ...


On my Arduino I am using this code:

p01title.setText(title);
delay(1000);
p03.show();
p02title.setText(title);
p03title.setText(title);

 The title gets updated on page 1 and page 3 because both paghes are active when the text is set.


But how can I set the text on an inactive page.


And/or how can I use the same text component on all pages?


Thank you


Something to try


On Page 0 in your HMI put a Variable component.  Set its vscope to global, set the sta to String.

Now either in the Page (Page1, Page2, etc) Post Initialization Event put the command

t0.txt=Page0.va0.txt

where t0 is the text component that will display the Title for the page, and

where va0 is the name of your global string variable on Page0


Doing this on each page should allow you to send the following command from your Arduino


va0.txt="My Nextion Project"


I think it is sent over a Serial.write() but don't quote me on Arduino issues.  If the title is consistant on all pages, you are not actually setting a text component on an inactive page, but rather setting it once the page has become active.  You can set an inactive page component with page1.title.txt="My Title", but it would be erased on entering and activating the page (all variables are set to what you had as default txt/val field of the components in your HMI design) and then after that initialization, the post initialize event kicks in.


Hope this was helpful







okay have a look at titles.hmi


you will see each page is initialized to "My Title"

if you send   page0.va0.txt="My Project Title"   the global variable is set

now as soon as a page is entered and gone back to, all titles on the pages have the new title.


To have your change reflected immediately

page0.va0.txt="My Project Title"

page0.t0.txt="My Project Title"  or (page1.title1.txt, page2.title2.txt, page3.title3.txt)



HMI
(17.4 KB)

1 person likes this

Great.
Thanks

Login or Signup to post a comment