parent
337c8b86ad
commit
e4264f70bf
@ -0,0 +1,8 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.12 (pythonProject1)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (pythonProject1)" project-jdk-type="Python SDK" />
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject1.iml" filepath="$PROJECT_DIR$/.idea/pythonProject1.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
Binary file not shown.
@ -0,0 +1,45 @@
|
||||
from tkinter import*
|
||||
import tkinter as tk
|
||||
|
||||
user_login ={'aaa':'123456','bbb':'888888','ccc':'333333'}
|
||||
count=0
|
||||
def login():
|
||||
global count
|
||||
username=entry_username.get()
|
||||
if username not in user_login:
|
||||
label_message.config(text='账号错误!')
|
||||
else:
|
||||
password=entry_password.get()
|
||||
if password == user_login[username]:
|
||||
label_message.config(text='登录成功!')
|
||||
def open_new_window():
|
||||
new_window = tk.Toplevel(root)
|
||||
# 在新窗口中创建新的界面
|
||||
root = tk.Tk()
|
||||
button = tk.Button(root, text="Open New Window", command=open_new_window)
|
||||
button.pack()
|
||||
root.mainloop()
|
||||
else:
|
||||
label_message.config(text='密码错误!还可以尝试{}次'.format(2-count))
|
||||
count=count+1
|
||||
if count == 3:
|
||||
label_message.config(text='登录失败!')
|
||||
btn_login.config(state='disabled')
|
||||
|
||||
window = Tk()
|
||||
window.title('用户登录')
|
||||
window.geometry('300x200')
|
||||
|
||||
label_username=Label(window,text="账号:")
|
||||
label_username.pack()
|
||||
entry_username = Entry(window)
|
||||
entry_username.pack()
|
||||
label_passsword = Label(window,text="密码:")
|
||||
label_passsword.pack()
|
||||
entry_password = Entry(window,show='*')
|
||||
entry_password.pack()
|
||||
btn_login=Button(window,text="登录",command=login)
|
||||
btn_login.pack()
|
||||
label_message=Label(window,text="")
|
||||
label_message.pack()
|
||||
window.mainloop()
|
@ -0,0 +1,126 @@
|
||||
class Warehouse:
|
||||
def __init__(self):
|
||||
# 使用字典存储商品及其库存,键为商品名称,值为库存数量
|
||||
self.inventory = {}
|
||||
|
||||
def add_item(self, item_name, quantity):
|
||||
"""添加商品到仓库"""
|
||||
if item_name in self.inventory:
|
||||
self.inventory[item_name] += quantity
|
||||
else:
|
||||
self.inventory[item_name] = quantity
|
||||
print(f"已添加 {quantity} 个 {item_name} 到仓库。")
|
||||
|
||||
def remove_item(self, item_name, quantity):
|
||||
"""从仓库移除商品"""
|
||||
if item_name not in self.inventory:
|
||||
print(f"{item_name} 不在仓库中。")
|
||||
return
|
||||
|
||||
if self.inventory[item_name] < quantity:
|
||||
print(f"库存不足,当前 {item_name} 只有 {self.inventory[item_name]} 个。")
|
||||
return
|
||||
|
||||
self.inventory[item_name] -= quantity
|
||||
if self.inventory[item_name] == 0:
|
||||
del self.inventory[item_name]
|
||||
print(f"已从仓库移除 {quantity} 个 {item_name}。")
|
||||
|
||||
def update_stock(self, item_name, new_quantity):
|
||||
"""更新商品的库存量"""
|
||||
if item_name not in self.inventory:
|
||||
print(f"{item_name} 不在仓库中,无法更新。")
|
||||
return
|
||||
|
||||
self.inventory[item_name] = new_quantity
|
||||
print(f"{item_name} 的库存已更新为 {new_quantity}。")
|
||||
|
||||
def check_stock(self, item_name=None):
|
||||
"""查询单个或所有商品的库存"""
|
||||
if item_name is None:
|
||||
# 打印所有库存
|
||||
for item, quantity in self.inventory.items():
|
||||
print(f"{item}: {quantity}")
|
||||
elif item_name in self.inventory:
|
||||
print(f"{item_name} 的库存为: {self.inventory[item_name]}")
|
||||
else:
|
||||
print(f"{item_name} 不在仓库中。")
|
||||
|
||||
|
||||
# 示例使用
|
||||
if __name__ == "__main__":
|
||||
warehouse = Warehouse()
|
||||
warehouse.add_item("苹果", 100)
|
||||
warehouse.add_item("香蕉", 150)
|
||||
warehouse.check_stock() # 查看所有库存
|
||||
warehouse.remove_item("苹果", 30)
|
||||
warehouse.update_stock("香蕉", 200)
|
||||
warehouse.check_stock("苹果") # 查询特定商品库存t("Invalid choice. Please try again.")
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
|
||||
class WarehouseGUI:
|
||||
def __init__(self, master):
|
||||
self.master = master
|
||||
master.title("仓库管理系统")
|
||||
|
||||
# 初始化仓库类
|
||||
self.warehouse = Warehouse()
|
||||
|
||||
# 商品名称输入框
|
||||
self.item_label = tk.Label(master, text="商品名称:")
|
||||
self.item_label.pack()
|
||||
self.item_entry = tk.Entry(master)
|
||||
self.item_entry.pack()
|
||||
|
||||
# 库存数量输入框
|
||||
self.quantity_label = tk.Label(master, text="库存数量:")
|
||||
self.quantity_label.pack()
|
||||
self.quantity_entry = tk.Entry(master)
|
||||
self.quantity_entry.pack()
|
||||
|
||||
# 操作选择下拉菜单
|
||||
self.operation_var = tk.StringVar(value="添加商品")
|
||||
self.operation_menu = tk.OptionMenu(master, self.operation_var, "添加商品", "减少库存", "更新库存", "查看库存")
|
||||
self.operation_menu.pack()
|
||||
|
||||
# 执行按钮
|
||||
self.execute_button = tk.Button(master, text="执行", command=self.execute_operation)
|
||||
self.execute_button.pack()
|
||||
|
||||
def execute_operation(self):
|
||||
operation = self.operation_var.get()
|
||||
item_name = self.item_entry.get()
|
||||
try:
|
||||
quantity = int(self.quantity_entry.get())
|
||||
except ValueError:
|
||||
messagebox.showerror("错误", "库存数量必须是整数!")
|
||||
return
|
||||
|
||||
if operation == "添加商品":
|
||||
self.warehouse.add_item(item_name, quantity)
|
||||
elif operation == "减少库存":
|
||||
self.warehouse.remove_item(item_name, quantity)
|
||||
elif operation == "更新库存":
|
||||
self.warehouse.update_stock(item_name, quantity)
|
||||
elif operation == "查看库存":
|
||||
if item_name:
|
||||
self.show_stock(item_name)
|
||||
else:
|
||||
self.show_all_stock()
|
||||
|
||||
def show_stock(self, item_name):
|
||||
stock = self.warehouse.check_stock(item_name)
|
||||
messagebox.showinfo(f"{item_name} 的库存", f"{stock}")
|
||||
|
||||
def show_all_stock(self):
|
||||
stock_info = "\n".join([f"{item}: {quantity}" for item, quantity in self.warehouse.inventory.items()])
|
||||
messagebox.showinfo("所有库存", stock_info)
|
||||
|
||||
def main():
|
||||
root = tk.Tk()
|
||||
app = WarehouseGUI(root)
|
||||
root.mainloop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -0,0 +1,51 @@
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from warehouse_gui import WarehouseGUI # 假设这是仓库管理系统的GUI类
|
||||
|
||||
|
||||
class LoginGUI:
|
||||
def __init__(self, master):
|
||||
self.master = master
|
||||
master.title("登录界面")
|
||||
|
||||
self.username_label = tk.Label(master, text="用户名:")
|
||||
self.username_label.pack()
|
||||
self.username_entry = tk.Entry(master)
|
||||
self.username_entry.pack()
|
||||
|
||||
self.password_label = tk.Label(master, text="密码:")
|
||||
self.password_label.pack()
|
||||
self.password_entry = tk.Entry(master, show="*")
|
||||
self.password_entry.pack()
|
||||
|
||||
self.login_button = tk.Button(master, text="登录", command=self.validate_login)
|
||||
self.login_button.pack()
|
||||
|
||||
def validate_login(self):
|
||||
username = self.username_entry.get()
|
||||
password = self.password_entry.get()
|
||||
|
||||
# 这里应该有一个验证用户名和密码的逻辑,比如查询数据库
|
||||
# 为了简化,这里直接使用硬编码的用户名和密码做示例
|
||||
valid_username = "admin"
|
||||
valid_password = "123456"
|
||||
|
||||
if username == valid_username and password == valid_password:
|
||||
messagebox.showinfo("登录成功", "欢迎,管理员!")
|
||||
self.master.destroy() # 销毁登录界面
|
||||
self.start_warehouse_app() # 启动仓库管理系统界面
|
||||
else:
|
||||
messagebox.showerror("登录失败", "用户名或密码错误!")
|
||||
|
||||
|
||||
|
||||
def start_warehouse_app(self):
|
||||
root = tk.Tk()
|
||||
WarehouseGUI(root) # 假设WarehouseGUI是仓库管理系统的主界面类
|
||||
root.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
login_root = tk.Tk()
|
||||
LoginGUI(login_root)
|
||||
login_root.mainloop()
|
Binary file not shown.
Loading…
Reference in new issue