[Question] PySide cannot accept a list of objects as the values for the Combobox element
還沒有人認領這個 Issue。
評估
研究方向
從 PySimpleGUIQt.py 中 Combo 的更新路徑開始,找到呼叫 self.QT_ComboBox.addItems(values) 的位置,並將其與處理物件值的初始化路徑進行比較。執行提供的 Point 重現程式,並確認使用物件更新 Combo 時顯示的是它們的字串值,而不是空白行。
由索引模型根據 Issue 內容生成。
描述
Type of Issue (Enhancement, Error, Bug, Question)
Question
Operating System
WIN10
PySimpleGUI Port (tkinter, Qt, Wx, Web)
Qt
Versions
Version information can be obtained by calling sg.main_get_debug_data()
Or you can print each version shown in ()
Python version (sg.sys.version)
Python 3.9.13
PySimpleGUI Version (sg.__version__)
5.0.0
GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi)
PySide2/PySide6
GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi)
PySide2/PySide6
Priority Support Code (Commercial Users)
Your Experience In Months or Years (optional)
5+ Years Python programming experience
10+ Years Programming experience overall
Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
tkinter
Anything else you think would be helpful?
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
- Searched main docs for your problem PySimpleGUI Documenation
- Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demo Programs
- None of your GUI code was generated by an AI algorithm like GPT
- If not tkinter - looked for Demo Programs for specific port
- For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
- Run your program outside of your debugger (from a command line)
- Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.com
- Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
- Tried running the Development Build. Your problem may have already been fixed but not released. Check Home Window for release notes and upgrading capability
- For licensing questions please email license@PySimpleGUI.com
Detailed Description
PySide2.QtWidgets.QComboBox.addItems(texts)
Parameters:
texts – list of strings
PySimpleGUI/tkinter can accept objects as values of widget, but PySimpleGUIQt/PySide cannot.
- Source code when initiate a Combobox, and it's fine.
items_as_strings = [str(v) for v in element.Values]
# element.QT_ComboBox.addItems(element.Values)
element.QT_ComboBox.addItems(items_as_strings)
- Source code when update a Combobox
self.QT_ComboBox.addItems(values)
You can find that there's no code to converts values to a list of str in PySimpleGUIQt.py when update, so we need to do it by ourself, or new values will be shown as blank lines in the Combobox element after updated.
Code To Duplicate
import PySimpleGUIQt as sg
class Point:
def __init__(self, location) -> None:
self.location = location
def __str__(self) -> str:
return f"Location {self.location}"
points = [Point(i) for i in range(5)]
window = sg.Window("Title", [[sg.Combo([0,1,2,3,4], key='COMBO')]], finalize=True)
window['COMBO'].update(values=points)
# window['COMBO'].update(values=tuple(map(str, points)))
window.read(close=True)
Screenshot, Sketch, or Drawing
Watcha Makin?
If you care to share something about your project, it would be awesome to hear what you're building.
- 主要語言
- Python
- 星號
- 13.8k
- 分支
- 1.8k
- PR 合併指標
- 30 天內沒有已合併 PR
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
PySimpleGUI/PySimpleGUI 的其他 Issue
-
Bug Done - Install Dev Build (see docs for how) Platform Specific Issue - Linux Port - TK
難度 2/5 1-3 小時 新手友好度 68/100
PySimpleGUI/PySimpleGUI#6904 · 15 則留言 ·
-
Bug Demo Programs Done - Install Dev Build (see docs for how) Interoperability Port - TK workaround available
難度 2/5 1-3 小時 新手友好度 68/100
PySimpleGUI/PySimpleGUI#6900 · 1 則留言 ·
-
Done - Install Dev Build (see docs for how) enhancement
難度 2/5 1-3 小時 新手友好度 62/100
PySimpleGUI/PySimpleGUI#3251 · 12 則留言 ·
-
難度 3/5 1-2 天 新手友好度 74/100
PySimpleGUI/PySimpleGUI#6906 · 1 則留言 · 1 個 reaction ·
-
Bug Done - Install Dev Build (see docs for how) Port - TK
難度 3/5 1-2 天 新手友好度 45/100
PySimpleGUI/PySimpleGUI#6902 · 1 則留言 ·
查看 PySimpleGUI/PySimpleGUI 的全部 Issue
相似的 Issue
-
fix: inaccuracy ⚠️
難度 2/5 1-3 小時 新手友好度 72/100
uabrc/uabrc.github.io#1255 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 84/100
ethereum-optimism/factory#64 ·
-
難度 2/5 1-3 小時 新手友好度 90/100
duckdb/duckdb-python#627 ·
-
難度 2/5 1-3 小時 新手友好度 68/100
-
documentation
難度 1/5 1 小時以內 新手友好度 78/100
Qiskit/qiskit-addon-sqd#376 ·