作者dritchie (Dennis MjY3OTk5)
看板Python
标题Re: [问题] 传递参数问题
时间Sun Dec 20 19:04:44 2015
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://webptt.com/cn.aspx?n=bbs/Python/M.1450609486.A.AFB.html