import tkinter as tk
import numpy as np
class chuangkou(object):
def __init__(self):
self.chuangkou = tk.Tk()
self.data = np.load('my_data.npy')
self.cishu = self.data[0]
self.jindu = self.data[1]
self.zongmubiao = 731
self.shuru = tk.Entry(self.chuangkou, width=10)
self.huabu = tk.Canvas(self.chuangkou, width=251, height=30, bg='black')
self.tuichu = tk.Button(self.chuangkou, text='退出', font=('华文新魏', 15), command=self.quit_part)
self.chongzhi = tk.Button(self.chuangkou, text='重置', font=('华文新魏', 15), command=self.chongzhi_part)
def main(self):
self.chuangkou.title('楠哥的计划进度')
self.main_jiemian()
self.chuangkou.mainloop()
def main_jiemian(self):
biaoti = tk.Label(self.chuangkou, text='燃料加载情况', font=('华文新魏', 30), fg='DeepSkyBlue')
biaoti.grid(column=1, row=0, columnspan=3)
tianshu = tk.Label(self.chuangkou, text='累计添加{}次'.format(self.cishu), font=('华文新魏', 10))
tianshu.grid(column=4, row=1)
yijiazai = tk.Label(self.chuangkou, text='已加载:', font=('华文新魏', 20))
yijiazai.grid(column=0, row=2, pady=20)
yijiazai = tk.Label(self.chuangkou, text='添加燃料:', font=('华文新魏', 15))
yijiazai.grid(column=1, row=3)
yijiazai = tk.Label(self.chuangkou, text='单位', font=('华文新魏', 15), padx=10)
yijiazai.grid(column=3, row=3)
anniu_weizhi = tk.Button(self.chuangkou, text='加入', command=self.jiaru_anniu, padx=10)
anniu_weizhi.grid(column=4, row=3)
self.tuichu.grid(column=0, row=4, sticky='w')
self.chongzhi.grid(column=4, row=4, sticky='e')
self.huabu.grid(column=1, row=2, columnspan=3)
self.shuru.grid(column=2, row=3)
self.jindutiao()
def jindutiao(self):
if self.jindu < self.zongmubiao:
jindu = (self.jindu / self.zongmubiao) * 100
else:
jindu = 100
changdu = (jindu / 100) * 250
jindu = format(jindu, '.2f')
changdu = format(changdu, '.2f')
self.huabu.create_rectangle(2.5, 2.5, 250, 29, fill='WhiteSmoke')
self.huabu.create_rectangle(2.5, 2.5, changdu, 29, fill='orange')
jindu1 = tk.Label(self.chuangkou, text='{}%'.format(jindu))
jindu1.grid(column=4, row=2, sticky='w', ipadx=15)
def jiaru_anniu(self):
jiaru = self.shuru.get()
self.jindu += int(jiaru)
self.cishu += 1
self.main()
def quit_part(self):
save_list = [self.cishu, self.jindu]
np.save('my_data.npy', save_list)
quit()
# @staticmethod
def chongzhi_part(self):
self.jindu = 0
self.cishu = 0
self.main()
def main():
try:
np.load('my_data.npy')
except FileNotFoundError:
save_list = [0, 0]
np.save('my_data.npy', save_list)
chengxu = chuangkou()
chengxu.main()
if __name__ == '__main__':
main()
61到64行是出问题的部分