Re: [問題] 傳遞參數問題

看板Python作者 (Dennis MjY3OTk5)時間10年前 (2015/12/20 19:04), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
from functools import partial for i in range(1, 10): btn[i]=Button(root,text='click',command=partial(a,i,i*2)) ※ 引述《IAMPF (PF)》之銘言: : 各位大大們好 : 最近在研究Tkinter寫視窗程式,遇到一個問題 : 比如我今天創一個Button : def a(): : print 'Hello' : b = Button(root, text='click', command=a) : 問題就在這個command=a : 通常a這個function不能帶參數 : 有辦法寫一個a是可以傳參數進去的嗎 : 比如 : def a(arg1, arg2): : print arg1, arg2 : 不知道要改的地方是在Button那邊還是說在a那邊 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.240.167.131 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1450609486.A.AFB.html
文章代碼(AID): #1MTejEhx (Python)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #1MTejEhx (Python)