You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.6 KiB
60 lines
1.6 KiB
import tkinter as tk
|
|
import tkinter.messagebox
|
|
from PIL import Image, ImageTk
|
|
|
|
|
|
|
|
window = tk.Tk()
|
|
window.title("my window")
|
|
window.geometry("450x300")
|
|
|
|
# welcome to image
|
|
canvas = tk.Canvas(window, height=200, width=500)
|
|
image_file = tk.PhotoImage(file="../image/img.png")
|
|
image = canvas.create_image(0, 0, anchor='nw', image=image_file)
|
|
canvas.pack(side='top')
|
|
|
|
|
|
# 电影名
|
|
tk.Label(window, text="电影名").place(x=100,y=230)
|
|
|
|
|
|
# 输入框
|
|
var_search = tk.StringVar()
|
|
var_search.set("哈尔的移动城堡")
|
|
entry_search = tk.Entry(window, textvariable=var_search)
|
|
entry_search.place(x=150,y=230)
|
|
|
|
def search_movie():
|
|
movie = entry_search.get()
|
|
if movie == "":
|
|
tk.messagebox.showwarning(title="错误", message="请输入电影名")
|
|
else:
|
|
# tk.messagebox.showinfo(title="搜索", message="你搜索了" + movie)
|
|
window_title = tk.Toplevel(window)
|
|
window_title.geometry("500x300")
|
|
window_title.title('《'+movie+'》'+"词云图")
|
|
|
|
# 加载图片
|
|
image = Image.open("../image/my_wordcloud.png")
|
|
image_resized = image.resize((400, 280))
|
|
photo_image = ImageTk.PhotoImage(image=image_resized)
|
|
|
|
# 创建Canvas并添加图片
|
|
canvas = tk.Canvas(window_title, width=image_resized.width, height=image_resized.height)
|
|
canvas.pack()
|
|
|
|
# 在Canvas上创建一个image对象
|
|
image_id = canvas.create_image(0, 0, anchor='nw', image=photo_image)
|
|
|
|
# 确保图片不会被垃圾回收
|
|
canvas.image = photo_image
|
|
|
|
|
|
# 搜索框
|
|
bth_search = tk.Button(window, text="搜索", command=search_movie)
|
|
bth_search.place(x=310,y=225)
|
|
|
|
|
|
window.mainloop()
|