1
這裏是PythonCard一個樣本資源文件:如何動態獲取GUI類中所有PythonCard組件的列表?
{ 'application':{ 'type':'Application',
'name':'Test Sounds',
'backgrounds':
[
{ 'type':'Background',
'name':'Test Sounds',
'title':'Test Sounds',
'position':(5, 5),
'size':(300, 200),
'components':
[
{ 'type':'TextField', 'name':'fldFilename', 'position':(5, 4), 'size':(200, -1), 'text':'anykey.wav' },
{ 'type':'Button', 'name':'btnFile', 'position':(210, 5), 'size':(-1, -1), 'label':'Select File' },
{ 'type':'Button', 'name':'btnPlay', 'position':(5, 40), 'size':(-1, -1), 'label':'Play' },
{ 'type':'CheckBox', 'name':'chkAsync', 'position':(5, 70), 'size':(-1, -1), 'label':'Async I/O', 'checked':0 },
{ 'type':'CheckBox', 'name':'chkLoop', 'position':(5, 90), 'size':(-1, -1), 'label':'Loop sound', 'checked':0 },
] } ] } }
有了這個源文件:
from PythonCard import model
class Sounds(model.Background):
# Some irrelevant methods... #
if __name__ == '__main__':
app = model.Application(Sounds)
app.MainLoop()
我將如何去動態取得所有的「按鈕」組件列表(例如)從GUI類內?
以self.components.<component name>
的方式訪問組件,所以我最初的想法是for x in self.components: ...
,但self.components
是不可迭代的。
我想答案與此有關:HTTP ://stackoverflow.com/questions/2352181/how-to-use-a-dot-to-access-members-of-dictionary – 2011-03-20 21:23:42
你解決了你的問題嗎? – 2011-06-30 02:14:31