泓霁全是问题 发表于 2020-3-28 12:04:45

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

http://p2.so.qhmsg.com/t02e153a5755725dfa7.jpg
之前在pycharm里点击"退出"按钮可以直接退出程序,但是用pyinstaller打包之后再运行时点击退出会出现图中的报错,但其他按钮都是正常的

admintest166 发表于 2020-3-28 12:19:56

你先把代码发出来先吧

看了一下你的这个报错 是quit没有被定义是不是你的这个方法没有写

泓霁全是问题 发表于 2020-3-28 12:39:31

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
      self.jindu = self.data
      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 =
      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 =
      np.save('my_data.npy', save_list)
    chengxu = chuangkou()
    chengxu.main()


if __name__ == '__main__':
    main()
61到64行是出问题的部分
页: [1]
查看完整版本: pyinstaller打包成exe后程序不能正常运行