鱼C论坛

 找回密码
 立即注册
查看: 604|回复: 2

pyinstaller打包成exe后程序不能正常运行

[复制链接]
发表于 2020-3-28 12:04:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

                               
登录/注册后可看大图

之前在pycharm里点击"退出"按钮可以直接退出程序,但是用pyinstaller打包之后再运行时点击退出会出现图中的报错,但其他按钮都是正常的
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-28 12:19:56 | 显示全部楼层
你先把代码发出来先吧

看了一下你的这个报错 是quit没有被定义  是不是你的这个方法没有写
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-28 12:39:31 | 显示全部楼层
  1. import tkinter as tk
  2. import numpy as np


  3. class chuangkou(object):

  4.     def __init__(self):
  5.         self.chuangkou = tk.Tk()
  6.         self.data = np.load('my_data.npy')
  7.         self.cishu = self.data[0]
  8.         self.jindu = self.data[1]
  9.         self.zongmubiao = 731
  10.         self.shuru = tk.Entry(self.chuangkou, width=10)
  11.         self.huabu = tk.Canvas(self.chuangkou, width=251, height=30, bg='black')
  12.         self.tuichu = tk.Button(self.chuangkou, text='退出', font=('华文新魏', 15), command=self.quit_part)
  13.         self.chongzhi = tk.Button(self.chuangkou, text='重置', font=('华文新魏', 15), command=self.chongzhi_part)

  14.     def main(self):
  15.         self.chuangkou.title('楠哥的计划进度')
  16.         self.main_jiemian()
  17.         self.chuangkou.mainloop()

  18.     def main_jiemian(self):
  19.         biaoti = tk.Label(self.chuangkou, text='燃料加载情况', font=('华文新魏', 30), fg='DeepSkyBlue')
  20.         biaoti.grid(column=1, row=0, columnspan=3)
  21.         tianshu = tk.Label(self.chuangkou, text='累计添加{}次'.format(self.cishu), font=('华文新魏', 10))
  22.         tianshu.grid(column=4, row=1)
  23.         yijiazai = tk.Label(self.chuangkou, text='已加载:', font=('华文新魏', 20))
  24.         yijiazai.grid(column=0, row=2, pady=20)
  25.         yijiazai = tk.Label(self.chuangkou, text='添加燃料:', font=('华文新魏', 15))
  26.         yijiazai.grid(column=1, row=3)
  27.         yijiazai = tk.Label(self.chuangkou, text='单位', font=('华文新魏', 15), padx=10)
  28.         yijiazai.grid(column=3, row=3)
  29.         anniu_weizhi = tk.Button(self.chuangkou, text='加入', command=self.jiaru_anniu, padx=10)
  30.         anniu_weizhi.grid(column=4, row=3)
  31.         self.tuichu.grid(column=0, row=4, sticky='w')
  32.         self.chongzhi.grid(column=4, row=4, sticky='e')
  33.         self.huabu.grid(column=1, row=2, columnspan=3)
  34.         self.shuru.grid(column=2, row=3)
  35.         self.jindutiao()

  36.     def jindutiao(self):
  37.         if self.jindu < self.zongmubiao:
  38.             jindu = (self.jindu / self.zongmubiao) * 100
  39.         else:
  40.             jindu = 100
  41.         changdu = (jindu / 100) * 250
  42.         jindu = format(jindu, '.2f')
  43.         changdu = format(changdu, '.2f')
  44.         self.huabu.create_rectangle(2.5, 2.5, 250, 29, fill='WhiteSmoke')
  45.         self.huabu.create_rectangle(2.5, 2.5, changdu, 29, fill='orange')
  46.         jindu1 = tk.Label(self.chuangkou, text='{}%'.format(jindu))
  47.         jindu1.grid(column=4, row=2, sticky='w', ipadx=15)

  48.     def jiaru_anniu(self):
  49.         jiaru = self.shuru.get()
  50.         self.jindu += int(jiaru)
  51.         self.cishu += 1
  52.         self.main()

  53.     def quit_part(self):
  54.         save_list = [self.cishu, self.jindu]
  55.         np.save('my_data.npy', save_list)
  56.         quit()

  57.     # @staticmethod
  58.     def chongzhi_part(self):
  59.         self.jindu = 0
  60.         self.cishu = 0
  61.         self.main()


  62. def main():
  63.     try:
  64.         np.load('my_data.npy')
  65.     except FileNotFoundError:
  66.         save_list = [0, 0]
  67.         np.save('my_data.npy', save_list)
  68.     chengxu = chuangkou()
  69.     chengxu.main()


  70. if __name__ == '__main__':
  71.     main()
复制代码

61到64行是出问题的部分
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-18 20:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表