Comments (10)
Hello @Antonio0307 , you don't need to write html to make a button. Look at this very simple example https://github.com/rawpython/remi/blob/master/examples/helloworld_app.py
from remi.
Hello@dddomodossola,Thank you for your reply!"https://github.com/rawpython/remi/blob/master/examples/helloworld_app.py" I know that way.But I want to know,In this "html" mode ,callback function of button,how to do it?
from remi.
“Callback function of button. ” ............... is it impossible to write in this mode?Because I want to take advantage of the existing HTML and CSS.I don't know. Can you understand my description?:)
from remi.
Hello @Antonio0307 ,
Here is an example for you
import remi.gui as gui
from remi import start, App
import os
class MyApp(App):
def init(self, *args):
res_path = os.path.join(os.path.dirname(os.path.abspath(file)), 'res')
super(MyApp, self).__init__(*args, static_file_path={'myres': res_path})
def idle(self):
pass
def main(self):
my_html_body = """
<body>
<div>
<button onclick="remi.sendCallback('%(emitter)s','%(listener_func_name)s')">BTN<button/>
<div/>
<body/>
"""%{'emitter':str(id(self)), 'listener_func_name':'onmousedown_btn'}
my_css_body = """
"""
self.page.children['body'].add_child('myhtml', my_html_body)
self.page.children['body'].add_child('mycss', my_css_body)
#self.page.children['body'].onmousedown.do(self.onmousedown_btn)
main_container = gui.Container()
return main_container
def onmousedown_btn(self):
print("BTN")
if __name__ == "__main__":
start(MyApp, debug=True, address='0.0.0.0', port=0, start_browser=True, username=None, password=None)
Have a nice day ;-)
from remi.
@dddomodossola Thank you very much for your quick and helpful response!!You are a master of “remi”! : ) What if there are several buttons ? "'emitter':str(id(self))"",I don't understand.It looks like a button id.I tried to do it, but it was wrong.
import remi.gui as gui
from remi import start, App
import os
class MyApp(App):
def init(self, *args):
res_path = os.path.join(os.path.dirname(os.path.abspath(file)), 'res')
super(MyApp, self).__init__(*args, static_file_path={'myres': res_path})
def idle(self):
pass
def main(self):
my_html_body = """
<body>
<div>
<button id = u1 onclick="remi.sendCallback('%(emitter)s','%(listener_func_name)s')">BTN<button/>
<button id = u2 onclick="remi.sendCallback('%(emitter)s','%(listener_func_name)s')">BTN<button/>
<div/>
<body/>
"""%{'emitter':str(id(self)), 'listener_func_name':'onmousedown_btn'}
my_css_body = """
"""
self.page.children['body'].add_child('myhtml', my_html_body)
self.page.children['body'].add_child('mycss', my_css_body)
#self.page.children['body'].onmousedown.do(self.onmousedown_btn)
main_container = gui.Container()
return main_container
def onmousedown_btn(self):
print("BTN")
def onmousedown_btn1(self):
print("BTN1")
if name == "main":
start(MyApp, debug=True, address='0.0.0.0', port=0, start_browser=True, username=None, password=None)
In fact, it is very simple to use the editor.In addition, I have successfully completed several projects,But I want to try new methods.Have a nice weekend!Great master! : )
from remi.
Hello @Antonio0307 ,
Excuse me for the late reply. str(id(self)) in this case is the identifier of the App class (the class who will receive the callback on button press). But it can be every remi widget.
Here is an example for multiple buttons:
import remi.gui as gui
from remi import start, App
import os
class MyApp(App):
def init(self, *args):
res_path = os.path.join(os.path.dirname(os.path.abspath(file)), 'res')
super(MyApp, self).__init__(*args, static_file_path={'myres': res_path})
def idle(self):
pass
def main(self):
my_html_body = """
<body>
<div>
<button id ="u1" onclick="remi.sendCallback('%(emitter)s','%(listener_func_name)s')" style="margin:5px">BTN<button/>
<button id ="u2" onclick="remi.sendCallback('%(emitter2)s','%(listener_func_name2)s')" style="margin:5px;background-color:red;">BTN1<button/>
<div/>
<body/>
"""%{'emitter':str(id(self)), 'listener_func_name':'onmousedown_btn',
'emitter2':str(id(self)), 'listener_func_name2':'onmousedown_btn1'}
my_css_body = """
"""
self.page.children['body'].add_child('myhtml', my_html_body)
self.page.children['body'].add_child('mycss', my_css_body)
#self.page.children['body'].onmousedown.do(self.onmousedown_btn)
main_container = gui.Container()
return main_container
def onmousedown_btn(self):
print("BTN")
def onmousedown_btn1(self):
print("BTN1")
if __name__ == "__main__":
start(MyApp, debug=True, address='0.0.0.0', port=0, start_browser=True, username=None, password=None)
Have a nice day ;-)
from remi.
Very strange!
Hello @Antonio0307 , Excuse me for the late reply. str(id(self)) in this case is the identifier of the App class (the class who will receive the callback on button press). But it can be every remi widget.
Here is an example for multiple buttons:
import remi.gui as gui from remi import start, App import os class MyApp(App): def init(self, *args): res_path = os.path.join(os.path.dirname(os.path.abspath(file)), 'res') super(MyApp, self).__init__(*args, static_file_path={'myres': res_path}) def idle(self): pass def main(self): my_html_body = """ <body> <div> <button id ="u1" onclick="remi.sendCallback('%(emitter)s','%(listener_func_name)s')" style="margin:5px">BTN<button/> <button id ="u2" onclick="remi.sendCallback('%(emitter2)s','%(listener_func_name2)s')" style="margin:5px;background-color:red;">BTN1<button/> <div/> <body/> """%{'emitter':str(id(self)), 'listener_func_name':'onmousedown_btn', 'emitter2':str(id(self)), 'listener_func_name2':'onmousedown_btn1'} my_css_body = """ """ self.page.children['body'].add_child('myhtml', my_html_body) self.page.children['body'].add_child('mycss', my_css_body) #self.page.children['body'].onmousedown.do(self.onmousedown_btn) main_container = gui.Container() return main_container def onmousedown_btn(self): print("BTN") def onmousedown_btn1(self): print("BTN1") if __name__ == "__main__": start(MyApp, debug=True, address='0.0.0.0', port=0, start_browser=True, username=None, password=None)Have a nice day ;-)
@dddomodossola Thank you for your reply!Very strange,My solution is the same as yours,But,report errors.That's why I asked you.It seems that I will find my own mistakes.........
from remi.
Which kind of errors you get?
from remi.
from remi.
from remi.
Related Issues (20)
- got an unexpected keyword argument 'websocket_port HOT 1
- Blank window on standalone_app.py HOT 2
- Labels do not display the correct number of whitespace HOT 1
- [QUESTION] any example of long-polling implementation in remi? HOT 1
- Get selected text from TextInput HOT 6
- automatic scroll down in text widget (write only) HOT 9
- highlight of table cells in front end. HOT 1
- GenericDialog confirm by Enter key pressing HOT 1
- 2 bugs remain for python 3.10 HOT 1
- How to add a radiobox or radiogroup in remi? HOT 1
- How to insert custom HTML
- Javascript gets unloaded after remi reloads with "handshake complete" HOT 3
- Add a button that opens a link HOT 2
- Feature request: Allow setting button labels on GenericDialog
- Editor: export do not work correctlly HOT 1
- Termux Version?
- Offline Plotly HTML Integration HOT 1
- Editor directory conflicts with other packages
- [Question] How can I find all the local partitions when working with gui.FileSelectionDialog widget? HOT 3
- Race condition when building single instance App gui
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remi.