Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Question] Use custom image for FileBrowse/FolderBrowse? #3148

Closed
8 tasks done
scmanjarrez opened this issue Jul 16, 2020 · 5 comments
Closed
8 tasks done

[ Question] Use custom image for FileBrowse/FolderBrowse? #3148

scmanjarrez opened this issue Jul 16, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@scmanjarrez
Copy link

scmanjarrez commented Jul 16, 2020

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

Question

Operating System

Ubuntu 18.04.4 LTS

Python version

Python 3.6.9

PySimpleGUI Port and Version

<module 'PySimpleGUI' from '$HOME/temp/test/lib/python3.6/site-packages/PySimpleGUI/__init__.py'>

4.24.0 Released 3-Jul-2020

Your Experience Levels In Months or Years

Python programming experience: 4 years.
Programming experience overall: 7 years.
Have used another Python GUI Framework (tkinter, Qt, etc) previously (yes/no is fine)? no.

You have completed these steps:

  • Read instructions on how to file an Issue
  • Searched through main docs http://www.PySimpleGUI.org for your problem
  • Searched through the readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Looked for Demo Programs that are similar to your goal http://www.PySimpleGUI.com
  • Note that there are also Demo Programs under each port on GitHub
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported
  • Try again by upgrading your PySimpleGUI.py file to use the current one on GitHub. Your problem may have already been fixed but is not yet on PyPI.

Description of question

Is it possible to use a custom icon for FileBrowse or FolderBrowse? I've seen those two shorcuts are just wrappers for Button, I thought I could use image_data, but didn't work.
I think I can imitate the functionality with a button, right?

Paste your code here

Code sample
#!/usr/bin/env python3
import PySimpleGUI as sg

sg.theme('LightBlue')	# Add a touch of color
# All the stuff inside your window.
filepng = "iVBORw0KGgoAAAANSUhEUgAAABMAAAAZCAYAAADTyxWqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAuQAAALkB4qdB6AAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAADlSURBVDiN7dW9SkNBEIbhRxO9A0kh/oAgsQ2kVfEqLFLkMmy8DRvrgFjbiWCV5B4CQirtrEQhCbHIHAzHKOeslueDj2WW3Xd2d2AHjjDEFPMC/sAdtq3QsCAk7xF2lkFrcaIarvC4KlvoAi08o4F1POEM42xRlqn7C0hcbY5bnGMS8RgHgp6im0g+wy4esJ8Kgx46Fs+0h+t6AuQY90vxK7ZwUgb2HmMjnNdGGdglXrCZmz/EaRYUreZP6maMvxTgmypYBatg/6a6xW9ZQxtvCYx2jDPSu1PeA2ii76tBlPUk9jc/AameX+bEqOgkAAAAAElFTkSuQmCC"

layout = [
    [sg.Text('Log File')],
    [sg.InputText('output/msf.log', key='inputlog'), sg.FileBrowse(target='inputlog', image_data=filepng)],
    ...
]

# Create the Window
window = sg.Window('AutoAuditor', layout)
# Event Loop to process "events" and get the "values" of the inputs
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == 'test':	# if user closes window or clicks cancel
        break
    print('You entered ', values[0])

window.close()

Obviously, I get an error:

Traceback (most recent call last):
  File "./gui.py", line 9, in <module>
    [sg.InputText('output/msf.log', key='inputlog'), sg.FileBrowse(target='inputlog', image_data=fa.icons['file'])],
TypeError: FileBrowse() got an unexpected keyword argument 'image_data'

Edit: Meanwhile, I'm creating the FileBrowser button beforehand, and then modifying the ImageData variable.

Thanks, very helpful tool.

@PySimpleGUI PySimpleGUI added the enhancement New feature or request label Jul 16, 2020
@PySimpleGUI
Copy link
Owner

I assume you mean to use an image on the button? It's not an icon in that case, it's a button image

@PySimpleGUI
Copy link
Owner

As a work-around, you can create your own File browse button with an image by copying the code for FileBrowse and adding the image (either filename or data) to the Button call.

Here's the FileBrowse code

def FileBrowse(button_text='Browse', target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), initial_folder=None,
               tooltip=None, size=(None, None), auto_size_button=None, button_color=None, change_submits=False,
               enable_events=False, font=None, disabled=False,
               pad=None, key=None, k=None, metadata=None):
    """

    :param button_text: text in the button (Default value = 'Browse')
    :type button_text: (str)
    :param target: key or (row,col) target for the button (Default value = (ThisRow, -1))
    :param file_types: filter file types (Default value = (("ALL Files", "*.*")))
    :type file_types: Tuple[Tuple[str, str], ...]
    :param initial_folder:  starting path for folders and files
    :param tooltip: text, that will appear when mouse hovers over the element
    :type tooltip: (str)
    :param size:  (w,h) w=characters-wide, h=rows-high
    :type size: (int, int)
    :param auto_size_button:  True if button size is determined by button text
    :type auto_size_button: (bool)
    :param button_color: button color (foreground, background)
    :type button_color: Tuple[str, str] or str
    :param change_submits: If True, pressing Enter key submits window (Default = False)
    :type change_submits: (bool)
    :param enable_events: Turns on the element specific events.(Default = False)
    :type enable_events: (bool)
    :param font: specifies the font family, size, etc
    :type font: Union[str, Tuple[str, int]]
    :param disabled: set disable state for element (Default = False)
    :type disabled: (bool)
    :param pad: Amount of padding to put around element in pixels (left/right, top/bottom)
    :type pad: (int, int) or ((int, int),(int,int)) or (int,(int,int)) or  ((int, int),int)
    :param key: key for uniquely identify this element (for window.FindElement)
    :type key: Union[str, int, tuple, object]
    :param k: Same as the Key. You can use either k or key. Which ever is set will be used.
    :type k: Union[str, int, tuple, object]
    :return: returns a button
    :rtype: (Button)
    """
    return Button(button_text=button_text, button_type=BUTTON_TYPE_BROWSE_FILE, target=target, file_types=file_types,
                  initial_folder=initial_folder, tooltip=tooltip, size=size, auto_size_button=auto_size_button,
                  change_submits=change_submits, enable_events=enable_events, disabled=disabled,
                  button_color=button_color, font=font, pad=pad, key=key, k=k, metadata=metadata)

@scmanjarrez
Copy link
Author

Yes, I mean an image. I'll use that, thank you very much.

@PySimpleGUI
Copy link
Owner

The only thing you really need to add to your button call is the button_type. That's what will control if it does a file browse, etc.

@PySimpleGUI
Copy link
Owner

And maybe a couple of the parameters that have default values (file types for example)

@scmanjarrez scmanjarrez changed the title [ Question] Use custom icon for FileBrowse/FolderBrowse? [ Question] Use custom image for FileBrowse/FolderBrowse? Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants