-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Comments
I assume you mean to use an image on the button? It's not an icon in that case, it's a button image |
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) |
Yes, I mean an image. I'll use that, thank you very much. |
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. |
And maybe a couple of the parameters that have default values (file types for example) |
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
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:
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
Obviously, I get an error:
Edit: Meanwhile, I'm creating the FileBrowser button beforehand, and then modifying the ImageData variable.
Thanks, very helpful tool.
The text was updated successfully, but these errors were encountered: