質問
Ubuntu 18.04.4 LTS
Python 3.6.9
<module 'PySimpleGUI' from '$HOME/temp/test/lib/python3.6/site-packages/PySimpleGUI/__init__.py'>
4.24.0 Released 3-Jul-2020
Pythonプログラミングの経験:4年。
プログラミング経験全体:7年。
以前に別のPythonGUIフレームワーク(tkinter、Qtなど)を使用したことがありますか(はい/いいえで問題ありません)? 番号。
FileBrowseまたはFolderBrowseにカスタムアイコンを使用することは可能ですか? これらの2つのショートカットはButtonの単なるラッパーであることがわかりました。image_dataを使用できると思いましたが、機能しませんでした。
ボタンで機能を真似できると思いますよね?
コードサンプル
#!/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()
明らかに、エラーが発生します。
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'
編集:その間、私は事前にFileBrowserボタンを作成してから、ImageData変数を変更しています。
おかげで、非常に役立つツール。
ボタンに画像を使うつもりですか? その場合はアイコンではなく、ボタンの画像です
回避策として、FileBrowseのコードをコピーし、画像(ファイル名またはデータ)をButton呼び出しに追加することで、画像を使用して独自のファイル参照ボタンを作成できます。
これがFileBrowseコードです
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)
はい、私はイメージを意味します。 使ってみます、ありがとうございます。
ボタン呼び出しに実際に追加する必要があるのは、button_typeだけです。 これが、ファイルの参照などを行うかどうかを制御するものです。
そして多分デフォルト値を持ついくつかのパラメータ(例えばファイルタイプ)