所需图片↓





import tkinter as tk
from tkinter import ttk
import joblib
import pandas
seasons_dict = {'春': 1, '夏': 2, '秋': 3, '冬': 4}
winds_dict = {'东北风': 1, '西北风': 2, '东南风': 3, '西南风': 4}
pics_dict ={'东南风':'images/东南风.gif',
'东北风':'images/东北风.gif',
'西南风':'images/西南风.gif',
'西北风':'images/西北风.gif'}
tips_dict ={'东南风':'预测结果:东南风','东北风':'预测结果:东北风','西南风':'预测结果:西南风','西北风':'预测结果:西北风'}
model = joblib.load('风向预测.pkl')
#以上是调用模型的代码
def show():
global img, tip
season_value = seasons_dict[season_combo.get()]
speed_value = speed_scale.get()
humi_value = humi_scale.get()
temp_value = temp_scale.get()
pres_value = pres_scale.get()
data = {}
data['季节'] = season_value
data['湿度'] = humi_value
data['气压'] = pres_value
data['温度'] = temp_value
data['风速'] = speed_value
df_data = pandas.DataFrame(data, index=[0])
y_pre = model.predict(df_data)
if y_pre == '东南风':
pic = pics_dict['东南风']
tip = tips_dict['东南风']
elif y_pre == '东北风':
pic = pics_dict['东北风']
tip = tips_dict['东北风']
elif y_pre == '西南风':
pic = pics_dict['西南风']
tip = tips_dict['西南风']
elif y_pre == '西北风':
pic = pics_dict['西北风']
tip = tips_dict['西北风']
img = tk.PhotoImage(file=pic)
info_label.config(text=tip)
img_label.config(image=img)
win = tk.Tk()
win.geometry('600x600')
win.title('风向预测工具')
season_label = tk.Label(win, text='季节:')
season_label.place(x=50, y=80)
season_combo = ttk.Combobox(win, width=12, values=['春', '夏', '秋', '冬'])
season_combo.current(0)
season_combo.place(x=100, y=80)
speed_scale = tk.Scale(win, label='风速:', from_=0, to=100, orient=tk.HORIZONTAL, tickinterval=50, length=200, resolution=0.1)
speed_scale.place(x=50, y=140)
temp_scale = tk.Scale(win, label='温度:',orient=tk.HORIZONTAL, from_=-20 ,to=40 ,tickinterval=20 ,length=200 )
temp_scale.place(x=50, y= 240)
humi_scale = tk.Scale(win, label='湿度:',orient=tk.HORIZONTAL, from_=0 ,to=100 ,tickinterval=50 ,length=200 )
humi_scale.place(x=50 , y=340 )
pres_scale = tk.Scale(win, label='气压:',orient=tk.HORIZONTAL, from_=990 ,to=1050 ,tickinterval= 30 ,length=200)
pres_scale.place(x=50 , y=440 )
submit_button = tk.Button(win, text='提交', width=10, command=show)
submit_button.place(x=100, y=550)
tip = '使用风向预测工具可以得到不同气侯情况下对应的风向'
info_label = tk.Label(win, text=tip, wraplength=270, justify='left', font=('黑体', 14))
info_label.place(x=300, y=150)
img = tk.PhotoImage(file='images/初始图片.gif')
img_label = tk.Label(win, image=img)
img_label.place(x=320, y=220)
win.mainloop()
241

被折叠的 条评论
为什么被折叠?



