Re: [问题] 传递参数问题

楼主: dritchie (卍~迈斯纳效应~卍)   2015-12-20 19:04:44
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那边

Links booklink

Contact Us: admin [ a t ] ucptt.com