Pysimplegui: Render html link in the text field

Created on 18 Sep 2018  路  8Comments  路  Source: PySimpleGUI/PySimpleGUI

It would be nice to be able to add link to some webpage in the gui.
Maybe some html rendering within the text input could do the job, I don know how complicated this can be.

ex:
<a href="www.github.com">Link to github</a>'

Done - Download from GitHub enhancement

Most helpful comment

In 3.5.0

All 8 comments

This is more or less a Text Element that returns to the caller when clicked, right? I could add an option to the Text Element, or create a new Link Element that is underlined returns when clicked.

I'm open to discussing this one as it's a good idea. Question is the implementation.

I guess you found that post about creating a hyperlink label with Tkinter too.

Maybe a Link element would allow to keep things simpler, rather than adding optional arguments to the Text Element. Well I have not looked at the source code but that's my gut feeling. And for beginners it might help to make the distinction too.

For this new Link element you would just request 2 arguments : the text to display and the text link to open, right ?

What if you want to have some normal text and at the end of the sentence the clickable link. Putting a Link Element next to a Text Element should do the job, I guess ?

ex : "Clic Here" would turn to something like [sg.Text("Clic"), sg.Link("Here", link="www.blabla.com")]

I am planning on having the form indicate the link was clicked by returning either the Text or the Key, just like buttons. Links are essentially buttons without the frame around them.

My plans are to include a flag within the Text Element that indicates it's 'clickable' rather than make a Link Element.

sg.Text('Here', is_link=True, key='link')

When clicked, this Text Element would return "link' as the button clicked.

sg.Text('Here', is_link=True')

This Element returns "here" if clicked

Would this design work with your program?

This would work indeed, I initially though that the callback action would happen under the hood.
But it makes sense to make the link return some string like for the buttons, such that one can do other actions than opening a webpage.

Done! Give this a whirl

import PySimpleGUI as sg

layout = [
          [sg.Text('This text is clickable', click_submits=True)],
          [sg.Text('This text is clickable with a key', click_submits=True, key='Text Key')],
          [sg.Text('This text is not clickable')],
          [sg.ReadButton('Button that does nothing')]
         ]

form = sg.FlexForm('Demo of clickable Text Elements').Layout(layout)

while True:
    button, values = form.Read()
    if button is None: break
    print(button, values)

Is it a problem if the text is not underlined?
With some work I could underline if if an option was set. It's a pain in the ass because you have to make a special style with underline capability.

While this is a cool feature, it's what I did while I was in the code that's super cool!

I made it possible to compact the code down by another line. I can't wait to update the Demos, cookbook!

Previously if you wanted to put your Read into a loop, that meant calling FlexForm and then a call to Layout. Like this:

form = sg.FlexForm('Demo of clickable Text Elements')
form.Layout(layout)

Now you can simply write:
form = sg.FlexForm('Demo of clickable Text Elements').Layout(layout)

I LOVE PYTHON!

I updated to the latest version (3.4.1) with pip but when I try to run the script above I have an argument exception
TypeError: __init__() got an unexpected keyword argument 'click_submits'

I tried checking the version in my python interpreter with sg.__version__ but there is not such argument, could you add it too ? It's a standard attribute for packages. Thanks

Right.... makes sense...
This new feature has not yet been released on PyPI.

It takes me a few days usually to migrate new features from Master Branch there.

Please download PySimpleGUI.py from here on GitHub to get this feature.

Generally speaking you can tell which features have not yet been released by looking at the Announcement Issue. If you see the feature after where I mark a release, you'll know it's not yet on PyPI.

In 3.5.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ihouses picture ihouses  路  6Comments

OPMUSER picture OPMUSER  路  5Comments

DKatarakis picture DKatarakis  路  6Comments

scmanjarrez picture scmanjarrez  路  5Comments

yogesh-aggarwal picture yogesh-aggarwal  路  3Comments