0

所以,我刚刚开始使用 PythonCard,我无法让最基本的应用程序工作:S 我试图在单击按钮时将 TextFields 中的值分配给变量;请看看你是否能理解问题所在:D

我的python主文件:

from PythonCard import model

class register(model.Background):
    def on_register_mouseClick(self, event):
        title = self.components.title.text
        artist = self.components.artist.text


if __name__ == '__main__':
    app = model.Application(register)
    app.MainLoop()

我的资源文件:

{'type':'CustomDialog',
    'name':'Template',
    'title':'Dialog Template',
    'position':(125, 125),
    'size':(300, 181),
    'components': [

{'type':'TextField', 
    'name':'artist', 
    'position':(115, 48), 
     'text':'artist', 
},

{'type':'TextField', 
    'name':'title', 
    'position':(116, 15), 
    'text':'title', 
    },

{'type':'Button', 
    'id':5100, 
    'name':'register', 
    'position':(10, 35), 
    'default':1, 
    'label':'OK', 
},

] # end components
} # end CustomDialog

提前致谢!:D

4

1 回答 1

3

您错误地使用 aCustomDialog而不是Application. 要解决您的问题,只需使用以下代码替换您的 rsrc 文件:

{'application':{'type':'Application',
          'name':'Template',
    'backgrounds': [
    {'type':'Background',
          'name':'Application',
          'title':u'Application',
          'size':(300, 181),

         'components': [

{'type':'Button', 
    'name':'register', 
    'position':(10, 35), 
    'default':True, 
    'label':u'OK', 
    },

{'type':'TextField', 
    'name':'title', 
    'position':(116, 15), 
    'text':u'title', 
    },

{'type':'TextField', 
    'name':'artist', 
    'position':(115, 48), 
    'text':u'artist', 
    },

] # end components
} # end background
] # end backgrounds
} }
于 2012-10-17T23:48:28.493 回答