parent
55a7d3f211
commit
4d5c29a216
@ -1,37 +1,59 @@
|
||||
import tkinter as tk
|
||||
import tkinter.messagebox
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
|
||||
|
||||
window = tk.Tk()
|
||||
window.title("my window")
|
||||
window.geometry("450x300")
|
||||
|
||||
# welcome image
|
||||
# welcome to image
|
||||
canvas = tk.Canvas(window, height=200, width=500)
|
||||
image_file = tk.PhotoImage(file="")
|
||||
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=150)
|
||||
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=150)
|
||||
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)
|
||||
# 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=145)
|
||||
bth_search.place(x=310,y=225)
|
||||
|
||||
|
||||
window.mainloop()
|
||||
|
Loading…
Reference in new issue