【发布时间】:2021-08-04 19:00:56
【问题描述】:
我想在 tkinter 中制作图像分类器:中间会有图像底部的 2 个按钮 ["one; two"],当我按下第一个按钮时,图像将转到文件夹 "one "
我尝试了很多变种,但无法解决这个问题; here is example
import tkinter as tk
from PIL import ImageTk, Image
from os import listdir
size= 700, 700
window = tk.Tk()
window.title("Join")
window.geometry("700x700")
window.minsize(700,700)
window.maxsize(700,700)
bottomFrame = tk.Frame(window)
bottomFrame.pack(fill=tk.X, side=tk.BOTTOM)
for i in range(2):
bottomFrame.columnconfigure(i, weight=1)
#commands
def one():
print("one")
im.save("one/"+ path)
def two():
print("two")
im.save("two/"+ path)
#loop
imagesList = listdir("all/")
for path in imagesList:
print("test")
im = Image.open("all/" + path)
im.thumbnail(size, Image.ANTIALIAS)
img = ImageTk.PhotoImage(im)
label = tk.Label(window, image = img)
label.pack(side = "top", fill = "both", expand = "true")
bluebutton = tk.Button(bottomFrame, text="one", fg="blue", command=one)
bluebutton1 = tk.Button(bottomFrame, text="two", fg="blue", command=two)
bluebutton.grid(row=0, column=0, sticky=tk.W+tk.E)
bluebutton1.grid(row=0, column=1, sticky=tk.W+tk.E)
window.mainloop()
【问题讨论】:
-
“不能解决这个问题” - 你为什么不能呢?当你尝试时会发生什么?您是否收到错误,如果是,错误是什么?您没有收到错误消息,但没有显示图像吗?它是否显示错误的图像?还有什么?
-
一/二函数的
path从何而来?