Python Tkinter按钮操作(Python Tkinter Button Action)
我有这个代码:
#!/usr/bin/python
import Tkinter
from tkFileDialog import askopenfilename
import tkMessageBox
root = Tkinter.Tk()
def getFileName():
# show an "Open" dialog box.
filename = askopenfilename(filetypes = [('Text files', '*.txt'),('All files','*')])
btnIco = Tkinter.Button(root, text="Icon", command=getFileName())
btnIco.pack()
root.mainloop()
我打算做的是在单击按钮时运行getFileName函数。 但是,当代码运行时,该函数会运行,而单击时按钮不会执行任何操作。 你能指出什么是错的吗?
I have this code:
#!/usr/bin/python
import Tkinter
from tkFileDialog import askopenfilename
import tkMessageBox
root = Tkinter.Tk()
def getFileName():
# show an "Open" dialog box.