ADD file via upload

main
plgk69mrf 6 months ago
parent 8c3fd50c67
commit f68c057453

@ -0,0 +1,288 @@
import tkinter
from tkinter import*
from tkinter import ttk
import tkinter as tk
import pymysql
from tkinter import Label
import mysql.connector
import turtle
from turtle import Screen, Turtle
from turtle import Canvas, RawTurtle
list1 = []
list2 =[]
canvas = None
db = pymysql.connect(host='localhost', user='root', password='123456', database='test', charset='utf8')
# 创建字典类型的游标对象
cursor = db.cursor()
#此处先留为避免后续可能对use_name数据段的游标造成影响
def update_data():
id_care = entry_id_care.get()
name = entry_name.get()
pack_id = entry_pack_id.get()
wuliu_info = entry_wuliu_info.get()
wuliu_info2 = entry_wuliu_info2.get()
wuliu_cant = entry_wuliu_cant.get()
sql = "UPDATE use_wuliu SET name = %s, pack_id = %s, wuliu_info = %s, wuliu_info2 = %s, wuliu_cant = %s WHERE id_care = %s"
values = (name, pack_id, wuliu_info, wuliu_info2, wuliu_cant, id_care)
cursor.execute(sql, values)
db.commit()
print("数据更新成功!")
entry_id_care.delete(0, tk.END)
entry_name.delete(0, tk.END)
entry_pack_id.delete(0, tk.END)
entry_wuliu_info.delete(0, tk.END)
entry_wuliu_info2.delete(0, tk.END)
entry_wuliu_cant.delete(0, tk.END)
def delete():
id_care = entry_id_care.get()
sql = "DELETE FROM use_wuliu WHERE id_care = %s"
value = (id_care,)
cursor.execute(sql, value)
db.commit()
print("数据删除成功!")
entry_id_care.delete(0, tk.END)
def add():
id_care = entry_id_care.get()
name = entry_name.get()
pack_id = entry_pack_id.get()
wuliu_info = entry_wuliu_info.get()
wuliu_info2 = entry_wuliu_info2.get()
wuliu_cant = entry_wuliu_cant.get()
sql = "INSERT INTO use_wuliu (id_care, name, pack_id, wuliu_info, wuliu_info2, wuliu_cant) VALUES (%s, %s, %s, %s, %s, %s)"
values = (id_care, name, pack_id, wuliu_info, wuliu_info2, wuliu_cant)
cursor.execute(sql, values)
db.commit()
print("数据插入成功!")
entry_id_care.delete(0, tk.END)
entry_name.delete(0, tk.END)
entry_pack_id.delete(0, tk.END)
entry_wuliu_info.delete(0, tk.END)
entry_wuliu_info2.delete(0, tk.END)
entry_wuliu_cant.delete(0, tk.END)
def draw_line():
text_drawr=text_drawrenew.get()
turtle.clear()
try:
cursor.execute("SELECT wuliu_info FROM use_wuliu WHERE id_care = %s", (text_drawr,))
except Exception as e:
print("发生了错误:", e)
row = cursor.fetchone()
if row is not None:
text_data = row[0]
else:
text_data = "Default Text"
cursor.execute("SELECT wuliu_info2 FROM use_wuliu WHERE id_care = %s", (text_drawr,))
row = cursor.fetchone()
if row is not None:
text_data1 = row[0]
else:
text_data1 = "Default Text"
t = RawTurtle(canvas)
t.speed(0)
# 画第一个点
t.penup()
t.goto(-50, 0)
t.shape("arrow")
t.stamp()
canvas.create_text(-40, 20, text=text_data, font=("Arial", 12))
# 画第二个点
t.goto(80, 0)
t.stamp()
canvas.create_text(70, 20, text=text_data1, font=("Arial", 12))
# 画直线连接两点
t.goto(-50, 0)
t.pendown()
t.goto(80, 0)
t.hideturtle()
class Logintabe:
def __init__(self):
self.window = tk.Tk()
self.window.title('物流管理系统')
self.window.geometry('300x300')
self.window.configure()
self.label_username = Label(self.window, text="账户:")
self.label_username.pack()
self.entry_username = Entry(self.window, width=20)
self.entry_username.pack()
self.label_password = Label(self.window, text="密码:")
self.label_password.pack()
self.entry_password = Entry(self.window, width=20, show="*")
self.entry_password.pack()
self.label_message = Label(self.window, text="")
self.label_message.pack()
self.btn_login = Button(self.window, text="登录", width=5, command=self.public_login)
self.btn_login.pack()
self.select = ttk.Combobox(self.window, width=8, textvariable=tk.StringVar(), state="readonly")
self.lis = ["管理人员", "客户"]
self.select['values'] = self.lis
self.select.pack()
def public_loginfarm(self):
self.window.mainloop()
def public_login(self):
input_username = self.entry_username.get()
input_password = self.entry_password.get()
cursor.execute("SELECT name, password FROM user_test WHERE name=%s", (input_username,))
result = cursor.fetchone()
if result:
list1 = result[0]
list2 = result[1]
if input_username == list1 and input_password == list2:
self.label_message.config(text="登录成功", bg="green")
self.window.destroy()
else:
self.label_message.config(text="登录失败", bg="red")
login_tab.public_loginfarm()
login_tab = Logintabe()
login_tab.public_loginfarm()
#登录页面功能实现
root = tkinter.Tk()
root.title("物流管理系统功能内容展示")
root.geometry('600x600')
note = ttk.Notebook()
note.place(relx=0.01, rely=0.08, relwidth=0.98, relheight=0.9)
frame3 = tkinter.Frame(root)
note.add(frame3, text='查看更新')
label_arenew = tkinter.Label(frame3, text="查看:")
label_arenew.pack()
text_arenew = tkinter.Entry(frame3)
text_arenew.pack()
id_text = tk.Text(frame3, height=10, width=10)
id_text.pack(side=tk.LEFT)
name_text = tk.Text(frame3, height=10, width=20)
name_text.pack(side=tk.LEFT)
pack_id_text = tk.Text(frame3, height=10, width=10)
pack_id_text.pack(side=tk.LEFT)
wuliu_info_text = tk.Text(frame3, height=10, width=20)
wuliu_info_text.pack(side=tk.LEFT)
wuliu_info2_text = tk.Text(frame3, height=10, width=20)
wuliu_info2_text.pack(side=tk.LEFT)
wuliu_cant_text = tk.Text(frame3, height=10, width=20)
wuliu_cant_text.pack(side=tk.LEFT)
serch_id_text = tk.Text(frame3, height=10, width=10)
serch_id_text.pack(side=tk.LEFT)
serch_name_text = tk.Text(frame3, height=10, width=20)
serch_name_text.pack(side=tk.LEFT)
serch_pack_id_text = tk.Text(frame3, height=10, width=10)
serch_pack_id_text.pack(side=tk.LEFT)
serch_wuliu_info_text = tk.Text(frame3, height=10, width=20)
serch_wuliu_info_text.pack(side=tk.LEFT)
serch_wuliu_info2_text = tk.Text(frame3, height=10, width=20)
serch_wuliu_info2_text.pack(side=tk.LEFT)
serch_wuliu_cant_text = tk.Text(frame3, height=10, width=20)
serch_wuliu_cant_text.pack(side=tk.LEFT)
def refresh_records():
# 清空所有文本框
for text_widget in text_widgets:
text_widget.delete("1.0", tk.END)
# 查询数据库中的信息
search_query = text_arenew.get()
cursor.execute("SELECT * FROM use_wuliu WHERE id_care=%s", (search_query,))
rows = cursor.fetchall()
cursor.execute("SELECT * FROM use_wuliu")
all_rows = cursor.fetchall()
# 将查询结果展示在各自的文本框中
for row in all_rows:
id_text.insert(tk.END, f"ID: {row[0]}\n")
name_text.insert(tk.END, f"Name: {row[1]}\n")
pack_id_text.insert(tk.END, f"Pack ID: {row[2]}\n")
wuliu_info_text.insert(tk.END, f"起始地: {row[3]}\n")
wuliu_info2_text.insert(tk.END, f"终点: {row[4]}\n")
wuliu_cant_text.insert(tk.END, f"状态: {row[5]}\n")
for row in rows:
serch_id_text.insert(tk.END, f"ID: {row[0]}\n")
serch_name_text.insert(tk.END, f"Name: {row[1]}\n")
serch_pack_id_text.insert(tk.END, f"Pack ID: {row[2]}\n")
serch_wuliu_info_text.insert(tk.END, f"起始地: {row[3]}\n")
serch_wuliu_info2_text.insert(tk.END, f"终点: {row[4]}\n")
serch_wuliu_cant_text.insert(tk.END, f"状态: {row[5]}\n")
mark_red(serch_id_text, f"ID: {row[0]}")
mark_red(serch_name_text, f"Name: {row[1]}")
mark_red(serch_pack_id_text, f"Pack ID: {row[2]}")
mark_red(serch_wuliu_info_text, f"起始地: {row[3]}")
mark_red(serch_wuliu_info2_text, f"终点: {row[4]}")
mark_red(serch_wuliu_cant_text, f"状态: {row[5]}")
def mark_red(text_widget, pattern):
start = "1.0"
while True:
pos = text_widget.search(pattern, start, tk.END)
if not pos:
break
end = f"{pos} + {len(pattern)} chars"
text_widget.tag_add("red", pos, end)
start = end
text_widget.tag_config("red", foreground="red")
text_widgets = [id_text, name_text, pack_id_text, wuliu_info_text, wuliu_info2_text, wuliu_cant_text]
refresh_button = tk.Button(root, text="更新", command=refresh_records)
refresh_button.pack()
frame1 = tkinter.Frame(root)
note.add(frame1, text='功能页面')
tk.Label(frame1, text="TD:").pack()
entry_id_care = tk.Entry(frame1, width=30)
entry_id_care.pack()
tk.Label(frame1, text="姓名:").pack()
entry_name = tk.Entry(frame1, width=30)
entry_name.pack()
tk.Label(frame1, text="包裹ID:").pack()
entry_pack_id = tk.Entry(frame1, width=30)
entry_pack_id.pack()
tk.Label(frame1, text="出发点:").pack()
entry_wuliu_info = tk.Entry(frame1, width=30)
entry_wuliu_info.pack()
tk.Label(frame1, text="终点:").pack()
entry_wuliu_info2 = tk.Entry(frame1, width=30)
entry_wuliu_info2.pack()
tk.Label(frame1, text="状态:").pack()
entry_wuliu_cant = tk.Entry(frame1, width=30)
entry_wuliu_cant.pack()
button1 = tkinter.Button(frame1, text='更新', width=5, command=update_data)
button1.pack()
buttonadd = tkinter.Button(frame1, text='增加', width=5, command=add)
buttonadd.pack()
buttonadd = tkinter.Button(frame1, text='删除', width=5, command=delete)
buttonadd.pack()
frame2 = tkinter.Frame(root, width=400, height=400)
note.add(frame2, text='物流信息页')
canvas = Canvas(frame2, width=200, height=200)
canvas.pack()
label_drawrenew = tkinter.Label(frame2, text="查看:")
label_drawrenew.pack()
text_drawrenew = tkinter.Entry(frame2)
text_drawrenew.pack()
button2 = tkinter.Button(frame2, text="查询", command=draw_line) # 将按钮存入框架2
button2.pack()
turtle = turtle.TurtleScreen(canvas)
turtle.bgcolor("white")
root.mainloop()
Loading…
Cancel
Save