- 论坛徽章:
- 0
|
遇到一个问题:如何获得python下button组件的text属性呢?- 2 import Tkinter
- 3 from Tkinter import *
- 4
- 5 def printtext(button):
- 6 hello.config(text=button.text())
- 7
- 8 top=Tkinter.Tk()
- 9
- 10 hello=Tkinter.Label(top,text='hello world')
- 11 hello.pack()
- 12
- 13 quit=Tkinter.Button(top,text='Quit',command=top.quit,bg='red',fg='white')
- 14
- 15 quit.pack(fill=Tkinter.X,expand=1)
- 16 buttonone=Tkinter.Button(top,text="one")
- 17 buttontwo=Tkinter.Button(top,text="two")
- 18 buttonone.config(command=printtext(buttonone))
- 19 buttontwo.config(command=printtext(buttontwo))
- 20 buttonone.pack(fill=Tkinter.X,expand=1);
- 21 buttontwo.pack(fill=Tkinter.X,expand=1);
- 22 buttonthree.pack(fill=Tkinter.X,expand=1);
- 23 Tkinter.mainloop()
复制代码 我使用了button.text和button.text()都不可以~
|
|