From fc0c2f67bdafd502697885503e949c5046c17e4f Mon Sep 17 00:00:00 2001 From: m6nsozqm4 <904360922@qq.com> Date: Sun, 27 Nov 2022 19:49:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BA=90=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bike.py | 211 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 src/bike.py diff --git a/src/bike.py b/src/bike.py new file mode 100644 index 0000000..15e4252 --- /dev/null +++ b/src/bike.py @@ -0,0 +1,211 @@ +import tkinter as tk +import requests + +import os +import time +import folium + +bikelist = [] + +def gd_map(addr): + para = {'key': '41dcdb5eec69991b0abd18baabd45f9d', # 高德Key + 'address': addr} # 地址参数 + url = 'https://restapi.amap.com/v3/geocode/geo?' # 高德地图地理编码API服务地址 + result = requests.get(url, para) # GET方式请求 + result = result.json() + lon_lat = result['geocodes'][0]['location'] # 获取返回参数geocodes中的location,即经纬度 + # print(result) + add = lon_lat.split(",") + + return [float(add[1]), float(add[0])] + + +def show_map(addr): + add = gd_map(addr=addr) + m = folium.Map(add, + tiles='https://wprd01.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=7', + attr='高德-常规图', + zoom_start=20, + ) + m.save("save.html") + + os.system("start save.html") +class bike: + ID: str + owner: str + price: float + borrower: str + can: bool + borrow_time: float + addr: str + + def __init__(self, ID, owner, price, addr): + self.ID = ID + self.owner = owner + self.price = price + self.borrower = "" + self.borrow_time = 0 + self.can = True + self.addr = addr + + def get_price(self): + price = float(self.price) * (time.time() - self.borrow_time) + return round(price, 2) + + def get_addr(self): + addr = gd_map(self.addr) + return addr +bikelist.append(bike("12345", "李华", "2.0", "天津市东丽区津北公路2898号中国民航大学北院")) +root = tk.Tk() +root.geometry("500x200+500+500") +root.title("自行车租赁管理") +def borrow(): + login_button1.focus_get() + borrow_window = tk.Toplevel(root) + borrow_window.geometry("500x200+500+500") + borrow_window.title("借车") + borrow_window.focus_get() + NameEntry = tk.Entry(borrow_window) + NameEntry.place(x=10, y=10, width=120, height=20) + list_bike = tk.Listbox(borrow_window, activestyle='dotbox') + for i in bikelist: + if i.can: + list_bike.insert(tk.END, "编号:" + i.ID + " 价格:" + i.price + " 位置:" + i.addr) + list_bike.pack() + + def borrow_bike(): + ID = NameEntry.get() + for i in bikelist: + if i.ID == ID: + i.borrow_time = time.time() + lable1 = tk.Label(borrow_window, text="借车成功") + show_map(i.addr) + i.can = False + lable1.pack() + + + else: + lable1 = tk.Label(borrow_window, text="未找到此车") + lable1.pack() + + ensure = tk.Button(borrow_window, text="借车", command=borrow_bike) + ensure.place(x=10, y=40, width=120, height=20) +def returnn(): + login_button1.focus_get() + return_window = tk.Toplevel(root) + return_window.geometry("500x200+500+500") + return_window.title("还车") + + list_bike = tk.Listbox(return_window, activestyle='dotbox') + for i in bikelist: + if not i.can: + print() + list_bike.insert(tk.END, + "编号:" + i.ID + " 价格:" + i.price + "租用时间:" + str(round(time.time() - i.borrow_time, 2))) + list_bike.pack() + + return_window.focus_get() + NameEntry = tk.Entry(return_window) + NameEntry.place(x=10, y=10, width=120, height=20) + addrEntry = tk.Entry(return_window) + addrEntry.place(x=10, y=40, width=120, height=20) + + def return_bike(): + ID = NameEntry.get() + addr = addrEntry.get() + for i in bikelist: + if i.ID == ID: + if not i.can: + price = i.get_price() + lable1 = tk.Label(return_window, text="还车成功,租用价格为" + str(price)) + lable1.pack() + i.can = True + i.addr = addr + break + + else: + lable1 = tk.Label(return_window, text="此车并未被借走") + lable1.pack() + break + + else: + lable1 = tk.Label(return_window, text="未找到此车") + lable1.pack() + + ensure = tk.Button(return_window, text="还车", command=return_bike) + ensure.place(x=10, y=70, width=120, height=20) +def add(): + login_button1.focus_get() + add_window = tk.Toplevel(root) + add_window.geometry("500x200+500+500") + add_window.title("出租车辆") + add_window.focus_get() + NameEntry = tk.Entry(add_window) + NameEntry.place(x=60, y=10, width=120, height=20) + lable1 = tk.Label(add_window, text="车辆ID") + lable1.place(x=10, y=10, width=50, height=20, ) + + autherEntry = tk.Entry(add_window) + autherEntry.place(x=60, y=40, width=120, height=20) + lable2 = tk.Label(add_window, text="车主名字") + lable2.place(x=10, y=40, width=50, height=20, ) + + majorEntry = tk.Entry(add_window) + majorEntry.place(x=60, y=70, width=120, height=20) + lable3 = tk.Label(add_window, text="租赁价格") + lable3.place(x=10, y=70, width=50, height=20, ) + + addrEntry = tk.Entry(add_window) + addrEntry.place(x=60, y=100, width=120, height=20) + lable4 = tk.Label(add_window, text="车辆位置") + lable4.place(x=10, y=100, width=50, height=20) + + def add_bike(): + ID = NameEntry.get() + owner = autherEntry.get() + price = majorEntry.get() + addr = addrEntry.get() + bikelist.append(bike(ID, owner, price, addr)) + + lable5 = tk.Label(add_window, text="添加车辆成功") + lable5.pack() + + ensure = tk.Button(add_window, text="出租车辆", command=add_bike) + ensure.place(x=200, y=10, width=120, height=20) +def dell(): + login_button1.focus_get() + del_window = tk.Toplevel(root) + del_window.geometry("500x200+500+500") + del_window.title("收回车辆") + del_window.focus_get() + list_bike = tk.Listbox(del_window, activestyle='dotbox') + for i in bikelist: + if i.can: + list_bike.insert(tk.END, "编号:" + i.ID + " 拥有者:" + i.owner) + list_bike.pack() + NameEntry = tk.Entry(del_window) + NameEntry.place(x=10, y=10, width=120, height=20) + + def del_bike(): + ID = NameEntry.get() + for i in bikelist: + if i.ID == ID: + del bikelist[bikelist.index(i)] + lable1 = tk.Label(del_window, text="收回车辆成功") + lable1.pack() + break + else: + lable1 = tk.Label(del_window, text="此车不存在") + lable1.pack() + + ensure = tk.Button(del_window, text="收回车辆", command=del_bike) + ensure.place(x=10, y=40, width=120, height=20) +login_button1 = tk.Button(root, text='租赁车辆', command=borrow) +login_button1.place(x=30, y=70, width=80, height=20) +login_button1 = tk.Button(root, text='归还车辆', command=returnn) +login_button1.place(x=120, y=70, width=80, height=20) +login_button1 = tk.Button(root, text='借出车辆', command=add) +login_button1.place(x=210, y=70, width=80, height=20) +login_button1 = tk.Button(root, text='收回车辆', command=dell) +login_button1.place(x=300, y=70, width=80, height=20) +root.mainloop() \ No newline at end of file