1

so I am making a small app, which searches the web via keyword in PyWebIO input() function and then shows results in put_table() and after the results are ready I need to start another search and instead of updating the page with F5 or browser, I want to create a put_button() which will update or get me back to input(), can anyone help, please? Im just not sure what should I put in onlick= attribute in this case.

3 Answers3

2
from pywebio.session import run_js

put_button("ReUpload_images",onclick=lambda: run_js('window.location.reload()'))
amks1
  • 43
  • 7
1

First, I'd like to quote from the pywebio documentation:

When you encounter a design problem when using PyWebIO, you can ask yourself a question: What would I do if it is in a terminal program?

The solution in terminal program is to put the input() and put_table() into a while loop. So, in pywebio, you can do the same thing:

from pywebio.input import * 
from pywebio.output import * 

while True:
    keyword = input()
    # make some query
    put_table(...)

The table will be appended to the page rather than be updated with this code. So do in terminal program. You can call pywebio.output.clear() after the input() to clear the page or use scope feature.

from pywebio.input import * 
from pywebio.output import * 

while True:
    keyword = input()
    # make some query
    with use_scope('result', clear=True):
        put_table(...)

When you use while True in server mode, you don't need to worry about the session will be running forever, because when you close the broswer tab, the pywebio will raise exception in your session to exit it.

In script mode, if you want to provide a way to exit the loop, you can:

from pywebio.input import * 
from pywebio.output import * 

while True:
    keyword = input()
    # make some query
    with use_scope('result', clear=True):
        put_table(...)
    if actions("Continue?",["continue", "exit"])=="exit":
        break
WangWeimin
  • 116
  • 5
1

You can add a button at the end and use run_js('window.location.reload()') to refresh the page. Check the demo on pyweb.io, and its source code

Helix
  • 36
  • 2
  • Please provide additional details in your answer. As it's currently written, it's hard to understand your solution. – Community Sep 04 '21 at 04:41
  • 1
    This answers works for me. I just put `run_js('window.location.reload()')` at the end of my callback to refresh the current page. – Adi Priyanto Nov 28 '21 at 16:19