You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.0 KiB

6 months ago
import tkinter as tk
import subprocess
import sys
6 months ago
6 months ago
def run_DayAir():
"""函数用于执行另一个Python脚本"""
try:
subprocess.run(["D:\Pycharm\Project\AirQuilitySys\.venv\Scripts\python.exe", "DayAir.py"], check=True)
except subprocess.CalledProcessError as e:
print(f"执行脚本时发生错误: {e}")
6 months ago
6 months ago
def run_DayAirzhu():
"""函数用于执行另一个Python脚本"""
try:
subprocess.run(["D:\Pycharm\Project\AirQuilitySys\.venv\Scripts\python.exe", "DayAirzhu.py"], check=True) # 尝试运行另一个Python脚本
except subprocess.CalledProcessError as e:
print(f"执行脚本时发生错误: {e}")
6 months ago
6 months ago
def run_DayAirbing():
"""函数用于执行另一个Python脚本"""
try:
subprocess.run(["D:\Pycharm\Project\AirQuilitySys\.venv\Scripts\python.exe", "DayAirbing.py"], check=True) # 尝试运行另一个Python脚本
except subprocess.CalledProcessError as e:
print(f"执行脚本时发生错误: {e}")
def run_time():
"""函数用于执行另一个Python脚本"""
try:
subprocess.run(["D:\Pycharm\Project\AirQuilitySys\.venv\Scripts\python.exe", "time.py"], check=True) # 尝试运行另一个Python脚本
except subprocess.CalledProcessError as e:
print(f"执行脚本时发生错误: {e}")
# 创建主窗口
window = tk.Tk()
window.title("执行外部程序示例")
# 创建一个按钮点击时调用run_another_program函数
but = tk.Button(window, text="查看每日空气折线分布图", command=run_DayAir)
but.pack(padx=20, pady=20) # 设置按钮布局
butt = tk.Button(window, text="查看每日空气柱状图", command=run_DayAirzhu)
butt.pack(padx=20, pady=20) # 设置按钮布局
butto = tk.Button(window, text="查看每月pm2.5平均指数", command=run_DayAirbing)
butto.pack(padx=20, pady=20) # 设置按钮布局
bu = tk.Button(window, text="查看未来预测数据", command=run_time)
bu.pack(padx=20, pady=20) # 设置按钮布局
# 运行Tkinter事件循环
window.mainloop()