我想为我刚写的程序创建一个Tkinter接口。界面需要有一个小部件,用户可以在其中插入要处理的程序的图像。我无法在网上找到这样的小部件。我该如何制作这样的界面?
答案 0 :(得分:0)
以下是tkinter条目小部件的示例,它立即接收图像:
try: # In order to be able to import tkinter for
import tkinter as tk # either in python 2 or in python 3
import tkinter.filedialog as tkfd
except ImportError:
import Tkinter as tk
import tkFileDialog as tkfd
if __name__ == '__main__':
root = tk.Tk()
entry = tk.Entry(root)
entry.pack()
path = tkfd.askopenfilename(initialdir = "/", title = "Select file",
filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
entry.insert('0', path)
root.mainloop()