任何人都可以幫我解決我的問題。我是新來的蟒蛇,我不能得到如何在下列情況下,一個參數傳遞給一個函數: 在一個單獨的文件(sentiment_analysis)我有一本字典和對象的數組:python Tkinter:將參數傳遞給函數
positiveSentiments = dict() // here are some words related to each of the object
objects = ['Google', 'Apple', 'Motorola']
我需要顯示每個對象的正面情緒:
def onButtonPosObject(p):
for key in sentiment_analysis.positiveSentiments.keys():
if key == p:
text.insert(END, sentiment_analysis.positiveSentiments[key])
submenu = Menu(text, tearoff=0)
for p in sentiment_analysis.objects:
submenu.add_command(label=p, command = lambda : onButtonPosObject(p), underline=0)
textmenu.add_cascade(label='Display positive sentiments', menu=submenu, underline=0)
我想我必須要通過標籤(p)的值作爲onButtonPosObject()函數的參數,我需要從positiveSentiments字典得到一個單詞列表,每對象,但我得到像[]的空值。 我會非常感謝任何建議!
這一工程!非常感謝! – 2012-04-24 06:23:54