【发布时间】:2014-10-28 11:32:28
【问题描述】:
尝试制作带有“打开文件”按钮的 GUI。当我运行下面显示的代码时,打开文件对话框会立即打开,而不是当我按下按钮时。为什么?有没有一种不涉及使用类的简单方法来解决这个问题? (我目前对课程一无所知,正在做一个时间紧迫的项目)
from tkinter import *
interface = Tk()
def openfile():
return filedialog.askopenfilename()
button = ttk.Button(interface, text = "Open", command = openfile())
button.grid(column = 1, row = 1)
interface.mainloop()
【问题讨论】:
标签: python user-interface python-3.x tkinter