【发布时间】:2021-09-14 19:05:38
【问题描述】:
我想构建一个 UI 来编辑 mp3 文件的 ID3v2 标签。我需要一个 StaticText - TextCtrl 列表来编辑不同的标签。我不想单独创建 StaticText 和 TextCtrl,而是想编写一个将它们结合起来的小部件。 我希望它看起来像这样:
我的第一个想法是扩展 BoxSizer 并使用 StaticText 和 TextCtrl 预填充它
import wx
class LabelTextSizer(wx.BoxSizer):
def __init__(self, label):
super().__init__(wx.HORIZONTAL)
self.label = wx.StaticText(self, label=label)
self.text = wx.TextCtrl(self)
self.Add(self.label)
self.Add(self.text)
但它并没有像我期望的那样工作:
Traceback (most recent call last):
File "D:\Tron\repo\rex-song-tagger\main.py", line 58, in <module>
frm = HelloFrame(None, title='Hello World 2')
File "D:\Tron\repo\rex-song-tagger\main.py", line 25, in __init__
sizer = LabelTextSizer('Title')
File "D:\Tron\repo\rex-song-tagger\LabelTextSizer.py", line 25, in __init__
self.label = wx.StaticText(self, label=label)
TypeError: StaticText(): arguments did not match any overloaded call:
overload 1: too many arguments
overload 2: argument 1 has unexpected type 'LabelTextSizer'
Process finished with exit code 1
你会如何以 wx 方式做到这一点?
【问题讨论】:
-
你想要一个小部件而不是一个sizer。
wx.ListBox可能是竞争者。
标签: python user-interface wxpython python-3.9