1

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'

1 Answers1

3

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

ikolim
  • 15,721
  • 2
  • 19
  • 29
  • I see. Maybe my problem is that I imported Webbrowser at the beginning of my code as opposed to within the builder string. – Adrain Chase98 Jun 05 '19 at 14:13
  • Welcome to Stack Overflow. If the Kivy app use `webbrowser` in the Python script then we put the import statement inside the script else we put it inside the *kv* file. If my answer has helped you, please accept the answer. Thank you. [If you accept someone else's answer: You gain +2 reputation](https://stackoverflow.com/help/accepted-answer) – ikolim Jun 05 '19 at 14:32