Pysimplegui: [Question] Ability to Update tooltip and initial_folder element attributes

Created on 13 Sep 2019  路  9Comments  路  Source: PySimpleGUI/PySimpleGUI

Type of Issues (Enhancement, Error, Bug, Question)

Enhancement

Operating System

Windows 10

Python version

3.7

PySimpleGUI Port and Version

4.5.0.3

Your Experience Levels In Months or Years

____1yr_____ Python programming experience
____3yrs_____ Programming experience overall
____No_____ Have used another Python GUI Framework (tkiner, Qt, etc) previously (yes/no is fine)?

You have completed these steps:

  • [x] Read instructions on how to file an Issue
  • [x] Searched through main docs http://www.PySimpleGUI.org for your problem
  • [x] Searched through the readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • [x] Looked for Demo Programs that are similar to your goal http://www.PySimpleGUI.com
  • [x] Note that there are also Demo Programs under each port on GitHub
  • [x] Run your program outside of your debugger (from a command line)
  • [x] Searched through Issues (open and closed) to see if already reported

Hi there Mike,

Just wanted to suggest, it would be great to be able to Update more attributes of some elements. For example, in a program I'm working on, I have several InputText elements with tooltips to display potentially long file paths, in addition to FolderBrowse elements with initial_folder values of those file paths. When the user browses to a new location and the InputText element displays the new path, I'd love for the tooltip to be updated as well, along with the initial_folder value to represent the new path chosen so that if the user Browses again, they're taken to the most recent path they chose.

Is this possible?

Thanks Mike!

Done - Download from GitHub documentation

All 9 comments

Maybe I'm missing something or you haven't found the set_tooltip method. Every element has a set_tooltip method. Or SetTooltip if you're using the old-style calls.

You should be able to do this to set the tooltip:

window[element_key].set_tooltip('new tooltip')

Can you send a screenshot of your application? I'm having a difficult time understanding the browse part. You're showing a window that keeps a folder browse button up all the time that the user utilizes more than once without closing the window between?

Here's the reference documentation on the Input element:
https://pysimplegui.readthedocs.io/en/latest/#inputtext-element

Among the methods you can call for an input element are these:
image

Every element in the docs has this SetTooltip method documented. Is this not the call you're looking for?

Re: tooltips -
SetTooltip did the trick! I was aware of the method, but I suppose I didn't fully understand what it was meant for given the purpose behind and existence of the Update method. I was essentially trying to do

window.FindElement(key).Update(tooltip='Tooltip text here')

and getting an "unexpected keyword argument ' tooltip'" error, but SetTooltip appears to accomplish what I was going for so, that works for me! Thank you!

Re: Browse buttons

You're showing a window that keeps a folder browse button up all the time that the user utilizes more than once without closing the window between?

Yes. Here is a sample program:

import PySimpleGUI_v4 as sg

def main():

    directory='C:\\'
    layout_Main = [[sg.InputText(directory, disabled=True, enable_events=True, key='_InputText01_'), sg.FolderBrowse(initial_folder=directory, key='_BrowseButton01_')]]

    window_Main = sg.Window('Test02').Layout(layout_Main)

    while True:
        event, values = window_Main.Read()
        print (event, '\n', values, '\n')

        if (event is None):
            break
        elif (event == '_InputText01_'):
            print ('InputText updated')
            #window_Main.FindElement('_BrowseButton01_').Update(initial_folder=values[event])

main()

I basically have browse buttons with initial_folder values set to some given directories when the window loads. When the user clicks a Browse button, the assigned initial_folder ("C:\" in the example program) is loaded up in the Browse window.

If the user navigates to and chooses a different folder (lets say "C:\Programs"), that folder is then displayed in the InputText element. If the user decides they want to choose a different folder, they click the Browse button again, and instead of being taken to the most recent folder they chose ("C:\Programs"), they're taken to "C:\" again because that's what is set as the Browse button's initial_folder.

What I'd like to be able to do is something like the commented line:
window_Main.FindElement('_BrowseButton01_').Update(initial_folder=values[event])
so that the Browse button will take the user to the most recently browsed location (i.e. whatever is in the InputText element), but this currently results in
TypeError: Update() got an unexpected keyword argument 'initial_folder'

I hope that makes better sense.

You can't just guess at parameters. Each element's Update method is unique and each is documented with both docstrings and in the written documentation. You get the error because, well, there isn't that parameter.

There is not a way to change that value at the moment. Let me look up the member variable that you probably can change.

Try setting the Browse Button's class variable InitialFolder to the value you want it to begin browsing. Add a key to your browse button.

Then you should be able to change it, at least for the tkinter port, using:

window[browse_buttons_key].InitialFolder = new_folder

Your suggestion to set the InitialFolder variable works perfectly! Thank you once again.

Just out of curiosity, when you implemented SetTooltip, was there a reason why you didn't go the Update(tooltip='') route instead? I assume the nature of how Update works may have simply made it difficult/not possible.

This particular implementation made it possible for me to get it written, documented and available for use a lot quicker than updating each of the Update methods.

I'll update the docs on how to use the .InitialFolder property since it works across all 4 ports this way. You can safely switch to Qt, Wx, Web and this implementation will work for them all.

Understood.

Thank you again for your time. 馃槉

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mozesa picture mozesa  路  5Comments

MikeTheWatchGuy picture MikeTheWatchGuy  路  3Comments

MikeTheWatchGuy picture MikeTheWatchGuy  路  5Comments

MikeTheWatchGuy picture MikeTheWatchGuy  路  6Comments

yogesh-aggarwal picture yogesh-aggarwal  路  3Comments