commit_0530

main
zy52306tg 6 months ago
parent e622d3554e
commit 9d0cd96046

@ -1 +0,0 @@
C:/Users/Admin/Pictures/Saved Pictures/0f754affcc469c034048cec299bdc149.jpgC:/Users/Admin/Pictures/Saved Pictures/0f754affcc469c034048cec299bdc149.jpg

@ -1,7 +1,5 @@
import tkinter as tk
from tkinter import messagebox
from upload import *
from test import *
from login_next import *
def login_1():
new_window = tk.Tk()
@ -16,14 +14,12 @@ def login_1():
root.pack()
# 创建按钮
create_table_button = tk.Button(root, text="创建表", command=create_table)
upload_image_button = tk.Button(root, text="上传图片", command=upload_image)
download_button = tk.Button(root, text="下载图片", command=download_image)
delete_button = tk.Button(root, text="删除图片", command=delete_image)
exit_button = tk.Button(root, text="返回", command=new_window.destroy)
# 布局
create_table_button.pack()
upload_image_button.pack()
download_button.pack()
delete_button.pack()

@ -25,12 +25,15 @@ def create_table():
with connection.cursor() as cursor:
cursor.execute(CREATE_TABLE_SQL)
connection.commit()
print("Table 'images' created successfully.")
finally:
connection.close()
def path_to_bytes():
return filedialog.askopenfilename(filetypes=(("Image Files", "*.jpg;*.png;*.gif"), ("All Files", "*.*")))
def upload_image():
# 创建数据库表
create_table()
# 选择要上传的图像文件
selected_image_path = path_to_bytes()
if selected_image_path:
with open(selected_image_path, 'rb') as image_file:

@ -24,7 +24,7 @@ def main():
login_button = tk.Button(root, text="登陆", command=main_0)
login_button.pack()
register_button = tk.Button(root, text="注册", command=register)
register_button = tk.Button(root, text="注册", command=register_jc)
register_button.pack()
exit_button = tk.Button(root, text="退出", command=root.destroy)
@ -37,10 +37,19 @@ def main_0():
# 这里可以添加用户名和密码的验证逻辑
if entered_username == query_user(entered_username).username and entered_password == query_user(entered_username).password:
login_1()
login_jc()
else:
erro_label = tk.Label(root, text="账号或密码错误")
erro_label.pack()
def register_jc():
root.destroy()
register()
def login_jc():
root.destroy()
login_1()
if __name__ == "__main__":
main()

@ -2,13 +2,6 @@ from flask import *
from flask_sqlalchemy import SQLAlchemy
import pymysql
import os
from tkinter import filedialog
import pymysql.cursors
DB_HOST = 'localhost' # 数据库主机
DB_USER = 'root' # 数据库用户名
DB_PASSWORD = '123456' # 数据库密码
DB_NAME = 'file' # 数据库名
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123456@localhost:3306/file'
@ -30,43 +23,6 @@ def add_user(username, password):
db.session.add(user)
db.session.commit()
def create_table():
connection = pymysql.connect(host=DB_HOST, user=DB_USER, password=DB_PASSWORD, db=DB_NAME)
try:
with connection.cursor() as cursor:
cursor.execute(CREATE_TABLE_SQL)
connection.commit()
print("Table 'images' created successfully.")
finally:
connection.close()
def path_to_bytes():
return filedialog.askopenfilename(filetypes=(("Image Files", "*.jpg;*.png;*.gif"), ("All Files", "*.*")))
def upload_image():
selected_image_path = path_to_bytes()
if selected_image_path:
with open(selected_image_path, 'rb') as image_file:
image_content = image_file.read()
connection = pymysql.connect(host=DB_HOST, user=DB_USER, password=DB_PASSWORD, db=DB_NAME)
try:
with connection.cursor() as cursor:
sql = "INSERT INTO images (filename, content) VALUES (%s, %s)"
cursor.execute(sql, (os.path.basename(selected_image_path), pymysql.Binary(image_content)))
connection.commit()
print(f"Image '{selected_image_path}' uploaded successfully.")
finally:
connection.close()
CREATE_TABLE_SQL = """
CREATE TABLE IF NOT EXISTS images (
id INT AUTO_INCREMENT PRIMARY KEY,
filename VARCHAR(255),
content LONGBLOB,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
"""
try:
with app.app_context():

@ -1,18 +0,0 @@
from tkinter import filedialog
import tkinter as tk
from sql import *
def upload_file_login():
new_window = tk.Tk()
new_window.title("欢迎来到上传界面")
new_window.geometry("600x200")
upload_file_button = tk.Button(new_window, text="上传图片", command=upload_image)
upload_file_button.pack()
back_button = tk.Button(new_window, text="返回", command=new_window.destroy)
back_button.pack()
new_window.mainloop()
Loading…
Cancel
Save