Compare commits
2 Commits
55a7d3f211
...
4bf39cc50a
Author | SHA1 | Date |
---|---|---|
|
4bf39cc50a | 9 months ago |
|
4d5c29a216 | 9 months ago |
@ -0,0 +1,30 @@
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
import mysql.connector
|
||||
|
||||
def connect_to_database():
|
||||
try:
|
||||
# 连接数据库
|
||||
connection = mysql.connector.connect(
|
||||
host="127.0.0.1",
|
||||
user="root",
|
||||
password="020425",
|
||||
database="douban"
|
||||
)
|
||||
cursor = connection.cursor()
|
||||
messagebox.showinfo("Success", "Connected to MySQL database successfully")
|
||||
return connection, cursor
|
||||
except Exception as e:
|
||||
messagebox.showerror("Error", f"Error connecting to MySQL database: {e}")
|
||||
|
||||
|
||||
root = tk.Tk()
|
||||
root.title("MySQL Database Example")
|
||||
|
||||
# 连接数据库
|
||||
connection, cursor = connect_to_database()
|
||||
|
||||
root.mainloop()
|
||||
|
||||
# 关闭数据库连接
|
||||
connection.close()
|
@ -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