Search code examples
python-3.xbuttonhyperlinkkivyonpress

How would I program a button to open a website?


I am creating a button in kivy and when pressed, I'd like it to direct the user to specific website. I am aware of creating a hyperlink but I don't know how to implement it in a button.

I have tried adding a hyperlink to the text: and to the on_press:. I have also tried to import webbrowser and use that but that has not successful.

Button:
    text:'Click here to visit our website'
    on_press: 'Not sure what to write here'

Solution

  • Use webbrowser open a website.

    main.py

    from kivy.base import runTouchApp
    from kivy.lang import Builder
    
    
    runTouchApp(Builder.load_string("""
    #:import webbrowser webbrowser
    
    Button:
        text: 'Goto Kivy Website'
        on_release: webbrowser.open('https://kivy.org/')
    """))
    

    Output

    App startup Open Kivy website