diff --git a/filesys/__pycache__/login.cpython-39.pyc b/filesys/__pycache__/login.cpython-39.pyc index 3482a5b..9661be5 100644 Binary files a/filesys/__pycache__/login.cpython-39.pyc and b/filesys/__pycache__/login.cpython-39.pyc differ diff --git a/filesys/__pycache__/login_next.cpython-39.pyc b/filesys/__pycache__/login_next.cpython-39.pyc new file mode 100644 index 0000000..aaec583 Binary files /dev/null and b/filesys/__pycache__/login_next.cpython-39.pyc differ diff --git a/filesys/__pycache__/sql.cpython-39.pyc b/filesys/__pycache__/sql.cpython-39.pyc index b380171..54489aa 100644 Binary files a/filesys/__pycache__/sql.cpython-39.pyc and b/filesys/__pycache__/sql.cpython-39.pyc differ diff --git a/filesys/__pycache__/test.cpython-39.pyc b/filesys/__pycache__/test.cpython-39.pyc deleted file mode 100644 index e62fc74..0000000 Binary files a/filesys/__pycache__/test.cpython-39.pyc and /dev/null differ diff --git a/filesys/__pycache__/upload.cpython-39.pyc b/filesys/__pycache__/upload.cpython-39.pyc deleted file mode 100644 index d489eff..0000000 Binary files a/filesys/__pycache__/upload.cpython-39.pyc and /dev/null differ diff --git a/filesys/file_paths.txt b/filesys/file_paths.txt deleted file mode 100644 index 442deee..0000000 --- a/filesys/file_paths.txt +++ /dev/null @@ -1 +0,0 @@ -C:/Users/Admin/Pictures/Saved Pictures/0f754affcc469c034048cec299bdc149.jpgC:/Users/Admin/Pictures/Saved Pictures/0f754affcc469c034048cec299bdc149.jpg \ No newline at end of file diff --git a/filesys/login.py b/filesys/login.py index 3933ca9..c5b78a6 100644 --- a/filesys/login.py +++ b/filesys/login.py @@ -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() diff --git a/filesys/test.py b/filesys/login_next.py similarity index 98% rename from filesys/test.py rename to filesys/login_next.py index 996ec1e..75308f6 100644 --- a/filesys/test.py +++ b/filesys/login_next.py @@ -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: diff --git a/filesys/main.py b/filesys/main.py index 75a693d..d8de539 100644 --- a/filesys/main.py +++ b/filesys/main.py @@ -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() diff --git a/filesys/sql.py b/filesys/sql.py index cf49018..6b4745a 100644 --- a/filesys/sql.py +++ b/filesys/sql.py @@ -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(): diff --git a/filesys/upload.py b/filesys/upload.py deleted file mode 100644 index c48a8a7..0000000 --- a/filesys/upload.py +++ /dev/null @@ -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() - -