鱼C论坛

 找回密码
 立即注册
查看: 1143|回复: 4

[已解决]pyinstaller打包

[复制链接]
发表于 2020-8-4 19:59:16 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 lawrence1357 于 2020-8-4 20:12 编辑

我的代码是好几个py文件,为什么打包之后运行不了,求解??还有一个问题就是,Register类里面back函数为什么调用LoginPage会报错呢,NameError,如果这么写有问题,那请问这样的返回应该怎么写
  1. from tkinter import *
  2. from LoginPage import *

  3. import os

  4. if __name__ == '__main__':
  5.     with open(r'file/users/users.txt', encoding='UTF-8')as user:
  6.         users = user.readlines()
  7.     with open(r'file/clients/clients.txt', encoding='UTF-8')as client:
  8.         clients = client.readlines()
  9.     with open(r'file/admins/admins.txt', encoding='UTF-8')as admin:
  10.         admins = admin.readlines()
  11.         try:
  12.             os.makedirs(r'D:/荣辉地产/users')
  13.             os.makedirs(r'D:/荣辉地产/clients')
  14.             os.makedirs(r'D:/荣辉地产/invitationcode')
  15.             os.makedirs(r'D:/荣辉地产/admins')
  16.             os.makedirs(r'D:/荣辉地产/authorizationcode')
  17.         except FileExistsError:
  18.             pass
  19.         finally:
  20.             with open(r'D:/荣辉地产/users/users.txt', 'w', encoding='UTF-8')as w_users:
  21.                 w_users.write('')
  22.             if users:
  23.                 for user_info in users:
  24.                     with open(r'D:/荣辉地产/users/users.txt', 'a', encoding='UTF-8')as w_users:
  25.                         w_users.write(user_info)
  26.             with open(r'D:/荣辉地产/clients/clients.txt', 'w', encoding='UTF-8')as w_clients:
  27.                 w_clients.write('')
  28.             if clients:
  29.                 for clients_info in clients:
  30.                     with open(r'D:/荣辉地产/clients/client.txt', 'a', encoding='UTF-8')as w_clients:
  31.                         w_clients.write(clients_info)
  32.             with open(r'D:/荣辉地产/admins/admins.txt', 'w', encoding='UTF-8')as w_clients:
  33.                 w_clients.write('')
  34.             if admins:
  35.                 for admins_info in admins:
  36.                     with open(r'D:/荣辉地产/admins/admins.txt', 'a', encoding='UTF-8')as w_admins:
  37.                         w_admins.write(admins_info)
  38.             with open(r'D:/荣辉地产/invitationcode/invitationcode.txt', 'w', encoding='UTF-8')as w_invitationcode:
  39.                 w_invitationcode.write('')
  40.             with open(r'D:/荣辉地产/authorizationcode/authorizationcode.txt', 'w',
  41.                       encoding='UTF-8')as w_authorizationcode:
  42.                 w_authorizationcode.write('')

  43.     root = Tk()
  44.     LoginPage(root)
  45.     root.mainloop()
复制代码
  1. from tkinter import *
  2. from tkinter.messagebox import *
  3. import re
  4. from EnterPage import *
  5. from Register import *
  6. from FindBackPassword import *


  7. class LoginPage:
  8.     def __init__(self, loginroot):

  9.         self.root = loginroot
  10.         self.root.title('登录')
  11.         self.root.minsize(360, 180)
  12.         self.root.maxsize(360, 180)
  13.         self.root.geometry('360x180+550-350')
  14.         self.createpage()

  15.     def createpage(self):
  16.         self.frame = Frame(self.root)
  17.         self.frame.pack()
  18.         Label(self.frame, text='用户名:', font=('幼圆', 11)).grid(row=0, sticky=W)
  19.         self.username = StringVar()
  20.         Entry(self.frame, textvariable=self.username).grid(row=0, column=1, columnspan=3, pady=20, ipadx=30, sticky=W)
  21.         Label(self.frame, text='密码:', font=('幼圆', 11)).grid(row=1, stick=W, pady=10)
  22.         self.password = StringVar()
  23.         Entry(self.frame, textvariable=self.password, show='*').grid(row=1, column=1, columnspan=3, pady=10, ipadx=30,
  24.                                                                      sticky=W)
  25.         self.admin_num = IntVar()
  26.         self.callback_password = Label(self.frame, text='忘记密码', fg='blue', cursor='hand2')
  27.         self.callback_password.grid(row=2, column=3, ipadx=10, pady=5, sticky=W)
  28.         self.callback_password.bind('<Button-1>', self.findback)

  29.         Checkbutton(self.frame, text='  管理员登录     ', variable=self.admin_num).grid(row=2, column=1, columnspan=2,
  30.                                                                                    ipadx=15, sticky=W)
  31.         self.admin_num.set(0)
  32.         Button(self.frame, text='登录', command=self.logincheck).grid(row=3, column=1, ipadx=10)
  33.         Button(self.frame, text='注册', command=self.register).grid(row=3, column=2, ipadx=10)
  34.         Button(self.frame, text='退出', command=quit).grid(row=3, column=3, ipadx=10)

  35.     def findback(self, event):
  36.         # self.root.gird_forget()
  37.         FindBackPassword(self.root)

  38.     def adminlogin(self):
  39.         pass

  40.     def logincheck(self):
  41.         print(self.admin_num.get())
  42.         if not self.admin_num.get():
  43.             with open(r'file/users/users.txt', encoding='UTF-8')as users_name_password:
  44.                 users = users_name_password.readlines()
  45.                 if users:
  46.                     name = []
  47.                     for user in users:
  48.                         name.append(user.split(',')[0])
  49.                     if self.username.get() and self.password.get():
  50.                         if self.username.get() in name:
  51.                             for user in users:
  52.                                 if self.username.get() == user.split(',')[0]:
  53.                                     password = re.search(r'.*', user.split(',')[1]).group()
  54.                                     if self.password.get() == password:
  55.                                         self.clear_entry()
  56.                                         self.frame.destroy()
  57.                                         EnterPage(self.root, user.split(',')[0])
  58.                                         break
  59.                                     else:
  60.                                         self.clear_entry()
  61.                                         showinfo(title='错误', message='用户名或密码不正确!')
  62.                                         break
  63.                         else:
  64.                             self.name_notfound()
  65.                     else:
  66.                         showinfo(title='错误', message='用户名或密码不能为空!')
  67.                 else:
  68.                     self.name_notfound()
  69.         else:
  70.             with open(r'file/admins/admins.txt', encoding='UTF-8')as admin_name_password:
  71.                 admins = admin_name_password.readlines()
  72.                 if admins:
  73.                     name = []
  74.                     for admin in admins:
  75.                         name.append(admin.split(',')[0])
  76.                     if self.username.get() and self.password.get():
  77.                         if self.username.get() in name:
  78.                             for admin in admins:
  79.                                 if self.username.get() == admin.split(',')[0]:
  80.                                     password = re.search(r'.*', admin.split(',')[1]).group()
  81.                                     if self.password.get() == password:
  82.                                         self.clear_entry()
  83.                                         self.frame.destroy()
  84.                                         EnterPage(self.root, admin.split(',')[0])
  85.                                         break
  86.                                     else:
  87.                                         self.clear_entry()
  88.                                         showinfo(title='错误', message='用户名或密码不正确!')
  89.                                         break
  90.                         else:
  91.                             showinfo(title='错误', message='"{}"不是管理员!'.format(self.username.get()))

  92.                     else:
  93.                         showinfo(title='错误', message='用户名或密码不能为空!')
  94.                 else:
  95.                     self.name_notfound()

  96.     def register(self):
  97.         self.frame.pack_forget()
  98.         Register(self.root)

  99.     def name_notfound(self):
  100.         showinfo(title='错误', message='用户名"{}"不存在!'.format(self.username.get()))
  101.         self.clear_entry()

  102.     def clear_entry(self):
  103.         self.username.set('')
  104.         self.password.set('')
复制代码
  1. from LoginPage import *
  2. from tkinter.messagebox import *
  3. from tkinter import *
  4. import re
  5. import os
  6. import Main


  7. class Register:

  8.     def __init__(self, register):
  9.         self.root = register
  10.         self.root.title('登录')
  11.         self.root.minsize(360, 280)
  12.         self.root.maxsize(360, 280)
  13.         self.root.geometry('360x280+550-350')
  14.         self.createpage()

  15.     def createpage(self):
  16.         self.frame = Frame(self.root)
  17.         self.frame.pack()
  18.         Label(self.frame, text='用户名:', font=('幼圆', 11)).grid(row=0, sticky=W)
  19.         self.username = StringVar()
  20.         Entry(self.frame, textvariable=self.username).grid(row=0, column=1, columnspan=3, pady=10, ipadx=30, sticky=W)
  21.         Label(self.frame, text='*', font=('幼圆', 10), fg='red').grid(row=0, column=4, pady=10, sticky=E)
  22.         Label(self.frame, text='密码:', font=('幼圆', 11)).grid(row=1, stick=W, pady=10)
  23.         self.password = StringVar()
  24.         Entry(self.frame, textvariable=self.password, show='*').grid(row=1, column=1, columnspan=3, pady=10, ipadx=30,
  25.                                                                      sticky=W)
  26.         Label(self.frame, text='*', font=('幼圆', 10), fg='red').grid(row=1, column=4, pady=10, sticky=E)
  27.         Label(self.frame, text='确认密码:', font=('幼圆', 11)).grid(row=2, stick=W, pady=10)
  28.         self.confirm_password = StringVar()
  29.         Entry(self.frame, textvariable=self.confirm_password, show='*').grid(row=2, column=1, columnspan=3, pady=10,
  30.                                                                              ipadx=30, sticky=W)
  31.         Label(self.frame, text='*', font=('幼圆', 10), fg='red').grid(row=2, column=4, pady=10, sticky=E)
  32.         Label(self.frame, text='密保问题:', font=('幼圆', 11)).grid(row=3, stick=W, pady=10)
  33.         self.password_question = StringVar()
  34.         Entry(self.frame, textvariable=self.password_question).grid(row=3, column=1, columnspan=3, pady=10,
  35.                                                                     ipadx=30,
  36.                                                                     sticky=W)
  37.         Label(self.frame, text='*', font=('幼圆', 10), fg='red').grid(row=3, column=4, pady=10, sticky=E)
  38.         Label(self.frame, text='密保答案:', font=('幼圆', 11)).grid(row=4, stick=W, pady=10)
  39.         self.password_answer = StringVar()
  40.         Entry(self.frame, textvariable=self.password_answer).grid(row=4, column=1, columnspan=3, pady=10,
  41.                                                                   ipadx=30,
  42.                                                                   sticky=W)
  43.         Label(self.frame, text='*', font=('幼圆', 10), fg='red').grid(row=4, column=4, pady=10, sticky=E)
  44.         self.admin_num = IntVar()
  45.         Checkbutton(self.frame, text='注册管理员', variable=self.admin_num).grid(row=5, column=2, columnspan=2, ipadx=15,
  46.                                                                             sticky=E)

  47.         Button(self.frame, text='注册', command=self.register_account).grid(row=6, column=1, ipadx=10)
  48.         Button(self.frame, text='返回', command=self.back).grid(row=6, column=2, ipadx=10)
  49.         Button(self.frame, text='退出', command=quit).grid(row=6, column=3, ipadx=10)

  50.     def register_account(self):
  51.         if self.username.get() and self.password.get() and self.confirm_password.get() and self.password_question.get() and self.password_answer.get():
  52.             if self.password.get() == self.confirm_password.get():
  53.                 if self.admin_num.get():
  54.                     admin_w_a = askyesno(title='系统提示', message='确定注册管理员?')
  55.                     if admin_w_a:
  56.                         self.pop_up_w = Toplevel()
  57.                         self.pop_up_w.title('授权码验证')
  58.                         self.pop_up_w.minsize(340, 130)
  59.                         self.pop_up_w.maxsize(340, 130)
  60.                         self.pop_up_w.geometry('340x130+560-360')
  61.                         Label(self.pop_up_w, text='').grid(row=0, column=0, sticky=E)
  62.                         Label(self.pop_up_w, text='授权码:', font=('幼圆', 11)).grid(row=1, column=0, sticky=E)
  63.                         self.auth_code = StringVar()
  64.                         Entry(self.pop_up_w, textvariable=self.auth_code).grid(row=1, column=1, ipadx=50, columnspan=2,
  65.                                                                                sticky=E)
  66.                         Button(self.pop_up_w, text='确定', command=self.authverification).grid(row=2, pady=10, ipadx=10,
  67.                                                                                              column=1)
  68.                         Button(self.pop_up_w, text='取消', command=self.cancelfunc).grid(row=2, ipadx=10, column=2)
  69.                 else:
  70.                     self.pop_up_w = Toplevel()
  71.                     self.pop_up_w.title('邀请码验证')
  72.                     self.pop_up_w.minsize(340, 130)
  73.                     self.pop_up_w.maxsize(340, 130)
  74.                     self.pop_up_w.geometry('340x130+560-360')
  75.                     Label(self.pop_up_w, text='').grid(row=0, column=0, sticky=E)
  76.                     Label(self.pop_up_w, text='邀请码:', font=('幼圆', 11)).grid(row=1, column=0, sticky=E)
  77.                     self.invi_code = StringVar()
  78.                     Entry(self.pop_up_w, textvariable=self.invi_code).grid(row=1, column=1, ipadx=50, columnspan=2,
  79.                                                                            sticky=E)
  80.                     Button(self.pop_up_w, text='确定', command=self.inviverification).grid(row=2, pady=10, ipadx=10,
  81.                                                                                          column=1)
  82.                     Button(self.pop_up_w, text='取消', command=self.cancelfunc).grid(row=2, ipadx=10, column=2)

  83.             else:
  84.                 self.password.set('')
  85.                 self.confirm_password.set('')
  86.                 showinfo(title='错误', message='两次密码不一致!')
  87.         else:
  88.             showinfo(title='错误', message='*号空格为必填项!')

  89.     def cancelfunc(self):
  90.         self.pop_up_w.destroy()

  91.     def inviverification(self):
  92.         if self.invi_code.get():
  93.             code_invi = self.invi_code.get()
  94.             user_name = []
  95.             temporary_code = []
  96.             with open(r'file/authorizationcode/authorizationcode.txt', encoding='UTF-8')as code_r:
  97.                 code_r_s = code_r.readlines()
  98.             for code in code_r_s:
  99.                 temporary_code.append(re.search(r'\w*', code).group())
  100.             if code_invi in temporary_code:
  101.                 with open(r'file/users/users.txt', encoding='UTF-8')as user:
  102.                     users = user.readlines()
  103.                 for user_user in users:
  104.                     if user_user != '\n':
  105.                         user_name.append(user_user.split(',')[0])
  106.                 if self.username.get() in user_name:
  107.                     showinfo(title='错误', message='用户名已存在,请更换用户名!')
  108.                 else:
  109.                     temporary_admin = '{},{},{},{}\n'.format(self.username.get(), self.password.get(),
  110.                                                              self.password_question.get(), self.password_answer.get())
  111.                     with open(r'file/users/users.txt', 'a', encoding='UTF-8')as user_info:
  112.                         user_info.write(temporary_admin)
  113.                     self.pop_up_w.destroy()
  114.                     showinfo(title='提示', message='注册成功,请重启程序登录!')
  115.                     exit()


  116.             else:
  117.                 showinfo(title='错误', message='邀请码不正确!')
  118.         else:
  119.             showinfo(title='错误', message='邀请码不能为空!')

  120.     def authverification(self):
  121.         if self.auth_code.get():
  122.             code_auth = self.auth_code.get()
  123.             admin_name = []
  124.             temporary_code = []
  125.             with open(r'file/authorizationcode/authorizationcode.txt', encoding='UTF-8')as code_r:
  126.                 code_r_s = code_r.readlines()
  127.             for code in code_r_s:
  128.                 temporary_code.append(re.search(r'\w*', code).group())
  129.             if code_auth in temporary_code:
  130.                 with open(r'file/admins/admins.txt', encoding='UTF-8')as admin:
  131.                     admins = admin.readlines()
  132.                 for admin_user in admins:
  133.                     if admin_user != '\n':
  134.                         admin_name.append(admin_user.split(',')[0])
  135.                 if self.username.get() in admin_name:
  136.                     showinfo(title='错误', message='管理员名称已存在,请更换管理员名称!')
  137.                 else:
  138.                     temporary_admin = '{},{},{},{}\n'.format(self.username.get(), self.password.get(),
  139.                                                              self.password_question.get(), self.password_answer.get())
  140.                     with open(r'file/admins/admins.txt', 'a', encoding='UTF-8')as admin_info:
  141.                         admin_info.write(temporary_admin)
  142.                     self.pop_up_w.destroy()
  143.                     showinfo(title='提示', message='管理员注册成功,请重启登录!')
  144.                     exit()

  145.             else:
  146.                 showinfo(title='错误', message='授权码不正确!')
  147.         else:
  148.             showinfo(title='错误', message='授权码不能为空!')

  149.     def back(self):
  150.         self.frame.destroy()
  151.         LoginPage(self.root)
  152.         #这里调用LoginPage为什么会报错,说NameError: name 'LoginPage' is not defined



  153.         # .pack()



复制代码
  1. from tkinter import *
  2. from tkinter.messagebox import *
  3. from Client import *
  4. import datetime


  5. class EnterPage:
  6.     def __init__(self, mainpage, username):
  7.         self.root = mainpage
  8.         self.username = username
  9.         self.root.title('客户信息-录入系统 当前使用人员-{}'.format(self.username))
  10.         self.root.minsize(560, 256)
  11.         self.root.maxsize(560, 256)
  12.         self.root.geometry('560x256+480-380')
  13.         self.createpage()

  14.     def createpage(self):
  15.         self.frame = Frame(self.root)
  16.         self.frame.pack()

  17.         Label(self.frame).grid(row=0, rowspan=2)
  18.         Label(self.frame, text='客户姓名:', font=('幼圆', 11)).grid(row=4, column=0, pady=10, sticky=E)
  19.         self.client_name = StringVar()
  20.         Entry(self.frame, textvariable=self.client_name).grid(row=4, column=1, columnspan=3, ipadx=20)
  21.         Label(self.frame, text='*', font=('幼圆', 10), fg='red').grid(row=4, column=4, pady=10, sticky=E)
  22.         Label(self.frame, text='客户电话:', font=('幼圆', 11)).grid(row=5, column=0, pady=10, sticky=E)
  23.         self.client_phone = StringVar()
  24.         Entry(self.frame, textvariable=self.client_phone).grid(row=5, column=1, columnspan=3, ipadx=20)
  25.         Label(self.frame, text='*', font=('幼圆', 10), fg='red').grid(row=5, column=4, pady=10, sticky=E)
  26.         Label(self.frame, text='客户证件号:', font=('幼圆', 11)).grid(row=6, column=0, pady=10, sticky=E)
  27.         self.client_id = StringVar()
  28.         Entry(self.frame, textvariable=self.client_id).grid(row=6, column=1, columnspan=3, ipadx=20)
  29.         Label(self.frame, text='销售员:', font=('幼圆', 11)).grid(row=7, column=0, pady=10, sticky=E)
  30.         self.salesman = StringVar()
  31.         Entry(self.frame, textvariable=self.salesman, state='readonly').grid(row=7, column=1, columnspan=3, ipadx=20)
  32.         self.salesman.set(self.username)
  33.         Button(self.frame, text='保存', command=self.save).grid(row=8, column=1, pady=10, ipadx=10)
  34.         Button(self.frame, text='查询', command=self.find).grid(row=8, column=2, pady=10, ipadx=10)
  35.         Button(self.frame, text='退出', command=quit).grid(row=8, column=3, pady=10, ipadx=10)

  36.     def save(self):
  37.         if not (self.client_name.get() and self.client_phone.get()):
  38.             if not self.client_name.get() and self.client_phone.get():
  39.                 showinfo(title='错误', message='客户姓名为必填项!')
  40.             elif self.client_name.get() and not self.client_phone.get():
  41.                 showinfo(title='错误', message='客户电话为必填项!')
  42.             else:
  43.                 showinfo(title='错误', message='*号为必填项!')
  44.         else:
  45.             if self.client_phone.get().isdigit() and len(self.client_phone.get()) == 11:
  46.                 client_id = self.client_id.get()
  47.                 if not client_id:
  48.                     client_id = '未录入'
  49.                     with open(r'file/clients/clients.txt', encoding='UTF-8')as client_info:
  50.                         clients = client_info.readlines()
  51.                         for client in clients:
  52.                             if client != '\n':
  53.                                 if client.split(',')[1] == self.client_phone.get():
  54.                                     salesman = re.search(r'.*', client.split(',')[3]).group()
  55.                                     showinfo(title='错误',
  56.                                              message='手机号为"{}"的客户已存在,登记姓名为"{}",录入人员"{}"!'.format(
  57.                                                  self.client_phone.get(),
  58.                                                  client.split(',')[0],
  59.                                                  salesman))
  60.                                     self.clear_entry()
  61.                                     break
  62.                         else:
  63.                             t = str(datetime.datetime.now()).split('.')[0]
  64.                             with open(r'file/clients/clients.txt', 'a', encoding='UTF-8')as client:
  65.                                 client.write(
  66.                                     '{},{},{},{},{}\n'.format(self.client_name.get(), self.client_phone.get(),
  67.                                                               client_id, self.salesman.get(), t))
  68.                                 showinfo(title='提示', message='保存成功!')
  69.                                 self.clear_entry()

  70.                 else:
  71.                     if len(self.client_id.get()) == 18:
  72.                         with open(r'file/clients/clients.txt', encoding='UTF-8')as client_info:
  73.                             clients = client_info.readlines()
  74.                             for client in clients:
  75.                                 if client != '\n':
  76.                                     salesman = re.search(r'.*', client.split(',')[3]).group()
  77.                                     if client.split(',')[1] == self.client_phone.get() or client.split(',')[
  78.                                         2] == self.client_id.get():
  79.                                         if client.split(',')[1] == self.client_phone.get() and client.split(',')[
  80.                                             2] == self.client_id.get():
  81.                                             showinfo(title='错误',
  82.                                                      message='手机号为"{}",证件号为"{}"的客户已存在,登记姓名为"{}",录入人员"{}"!'.format(
  83.                                                          self.client_phone.get(), self.client_id.get(),
  84.                                                          client.split(',')[0],
  85.                                                          salesman))
  86.                                             self.clear_entry()
  87.                                             break
  88.                                         elif client.split(',')[1] == self.client_phone.get() and client.split(',')[
  89.                                             2] != self.client_id.get():
  90.                                             showinfo(title='错误',
  91.                                                      message='手机号为"{}"的客户已存在,登记姓名为"{}",录入人员"{}"!'.format(
  92.                                                          self.client_phone.get(), client.split(',')[0], salesman))
  93.                                             self.clear_entry()
  94.                                             break
  95.                                         elif client.split(',')[1] != self.client_phone.get() and client.split(',')[
  96.                                             2] == self.client_id.get():
  97.                                             showinfo(title='错误',
  98.                                                      message='证件号为"{}"的客户已存在,登记姓名为"{}",录入人员"{}"!'.format(
  99.                                                          self.client_id.get(), client.split(',')[0], salesman))
  100.                                             self.clear_entry()
  101.                                             break

  102.                             else:
  103.                                 t = str(datetime.datetime.now()).split('.')[0]
  104.                                 with open(r'file/clients/clients.txt', 'a', encoding='UTF-8')as client:
  105.                                     client.write(
  106.                                         '{},{},{},{},{}\n'.format(self.client_name.get(), self.client_phone.get(),
  107.                                                                   client_id, self.salesman.get(), t))
  108.                                     showinfo(title='提示', message='保存成功!')
  109.                                     self.clear_entry()
  110.                     else:
  111.                         showinfo(title='错误', message='证件号码错误!')
  112.             else:
  113.                 showinfo(title='错误', message='电话号码错误!')
  114.                 self.client_phone.set('')

  115.     def find(self):
  116.         self.frame.destroy()
  117.         Client(self.root, self.username)

  118.     def clear_entry(self):
  119.         self.client_name.set('')
  120.         self.client_phone.set('')
  121.         self.client_id.set('')
复制代码
  1. from tkinter import *
  2. from tkinter import filedialog
  3. from tkinter.messagebox import *
  4. import re
  5. import openpyxl


  6. class Client:
  7.     def __init__(self, root, username):
  8.         self.username = username
  9.         self.root = root
  10.         self.root.title('客户信息-查询系统 当前使用人员-{}'.format(self.username))
  11.         self.root.minsize(995, 570)
  12.         self.root.maxsize(995, 570)
  13.         self.root.geometry('995x570+360-180')
  14.         self.createpage()
  15.         clients_info = self.find()
  16.         self.clear_text()
  17.         new_clients = []
  18.         for clients in clients_info:
  19.             if clients != '\n':
  20.                 if self.username == clients.split(',')[3]:
  21.                     new_clients.append(clients)
  22.         for new_client in new_clients:
  23.             information = '客户姓名:' + new_client.split(',')[0] + '\t' + '客户电话:' + new_client.split(',')[
  24.                 1] + '\t' + '客户证件号码:' + new_client.split(',')[2] + '\t' + '销售员:' + \
  25.                           new_client.split(',')[3] + '\t' + '录入时间:' + new_client.split(',')[4]
  26.             self.text.insert(END, information)

  27.     def createpage(self):
  28.         self.frame = Frame(self.root)
  29.         self.frame.pack(fill=BOTH)

  30.         Label(self.frame, text='通过姓名查询:').grid(row=0, column=0, padx=5, pady=5)
  31.         self.name = StringVar()
  32.         Entry(self.frame, textvariable=self.name).grid(row=0, column=1, padx=5, pady=5)
  33.         Button(self.frame, text='查询', command=self.namefind).grid(row=0, column=2, padx=5, pady=5)

  34.         Label(self.frame, text='通过电话查询:').grid(row=0, column=3, padx=5, pady=5)
  35.         self.phone = StringVar()
  36.         Entry(self.frame, textvariable=self.phone).grid(row=0, column=4, padx=5, pady=5)
  37.         Button(self.frame, text='查询', command=self.phonefind).grid(row=0, column=5, padx=5, pady=5)

  38.         Label(self.frame, text='通过证件查询:').grid(row=0, column=6, padx=5, pady=5)
  39.         self.id_nub = StringVar()
  40.         Entry(self.frame, textvariable=self.id_nub).grid(row=0, column=7, padx=5, pady=5)
  41.         Button(self.frame, text='查询', command=self.idfind).grid(row=0, column=8, padx=5, pady=5)

  42.         Button(self.frame, text='查询所有', command=self.allfind).grid(row=0, column=9, padx=5, pady=5)

  43.         self.text = Text(self.frame)
  44.         self.text.grid(row=1, column=0, columnspan=10, ipadx=210, ipady=80, padx=5, pady=5,
  45.                        sticky=NSEW)
  46.         Button(self.frame, text='导出Excel', command=self.export).grid(row=2, column=9, padx=5, pady=5)

  47.     def export(self):
  48.         clients = self.find()
  49.         selfclients = []
  50.         excel_title = ['姓名', '联系方式', '证件号码', '营销人员', '登记时间']
  51.         workbook = openpyxl.Workbook()
  52.         worksheet = workbook.active
  53.         worksheet.append(excel_title)
  54.         for client in clients:
  55.             if client != '\n':
  56.                 if self.username == client.split(',')[3]:
  57.                     selfclients.append(client)
  58.         for selfclient in selfclients:
  59.             client_list = selfclient.split(',')
  60.             worksheet.append(client_list)
  61.         filepath = self.callback()

  62.         workbook.save(filepath)

  63.     def callback(self):
  64.         filepath = filedialog.asksaveasfilename(defaultextension='.xlsx', filetypes=[("XLSX", ".xlsx")])
  65.         return filepath

  66.     def find(self):
  67.         with open(r'file/clients/clients.txt', encoding='UTF-8')as client_info:
  68.             clients = client_info.readlines()
  69.             return clients

  70.     def namefind(self):
  71.         new_name = self.name.get().strip()
  72.         self.clear_text()
  73.         self.clear_entry()
  74.         if new_name:
  75.             clients = self.find()
  76.             new_clients = []
  77.             names = []
  78.             for client in clients:
  79.                 if client != '\n':
  80.                     if self.username == client.split(',')[3]:
  81.                         new_clients.append(client)
  82.                         names.append(client.split(',')[0])
  83.             if new_name in names:
  84.                 for new_client in new_clients:
  85.                     if new_name == new_client.split(',')[0]:
  86.                         information = '客户姓名:' + new_client.split(',')[0] + '\t' + '客户电话:' + new_client.split(',')[
  87.                             1] + '\t' + '客户证件号码:' + new_client.split(',')[2] + '\t' + '销售员:' + \
  88.                                       new_client.split(',')[3] + '\t' + '录入时间:' + new_client.split(',')[4]
  89.                         self.text.insert(END, information)

  90.             else:
  91.                 showinfo(title='错误', message='未录入此客户!')
  92.         else:
  93.             showinfo(title='错误', message='查询索引不能空!')

  94.     def allfind(self):
  95.         clients_info = self.find()
  96.         self.clear_text()
  97.         new_clients = []
  98.         for clients in clients_info:
  99.             if clients != '\n':
  100.                 if self.username == clients.split(',')[3]:
  101.                     new_clients.append(clients)
  102.         for new_client in new_clients:
  103.             information = '客户姓名:' + new_client.split(',')[0] + '\t' + '客户电话:' + new_client.split(',')[
  104.                 1] + '\t' + '客户证件号码:' + new_client.split(',')[2] + '\t' + '销售员:' + \
  105.                           new_client.split(',')[3] + '\t' + '录入时间:' + new_client.split(',')[4]
  106.             self.text.insert(END, information)

  107.     def phonefind(self):
  108.         new_phone = self.phone.get().strip()
  109.         self.clear_text()
  110.         self.clear_entry()
  111.         if new_phone:
  112.             if len(new_phone) == 11 and new_phone.isdigit():
  113.                 clients = self.find()
  114.                 new_clients = []
  115.                 phones = []
  116.                 for client in clients:
  117.                     if client != '\n':
  118.                         if self.username == client.split(',')[3]:
  119.                             new_clients.append(client)
  120.                             phones.append(client.split(',')[1])
  121.                 if new_phone in phones:
  122.                     for client in new_clients:
  123.                         if new_phone == client.split(',')[1]:
  124.                             information = '客户姓名:' + client.split(',')[0] + '\t' + '客户电话:' + client.split(',')[
  125.                                 1] + '\t' + '客户证件号码:' + client.split(',')[2] + '\t' + '销售员:' + \
  126.                                           client.split(',')[3] + '\t' + '录入时间:' + client.split(',')[4]
  127.                             self.text.insert(END, information)
  128.                             break

  129.                 else:
  130.                     showinfo(title='错误', message='未录入此号码!')

  131.             else:
  132.                 showinfo(title='错误', message='输入非法的号码!')
  133.         else:
  134.             showinfo(title='错误', message='查询索引不能空!')

  135.     def idfind(self):
  136.         new_id = self.id_nub.get().strip()
  137.         self.clear_text()
  138.         self.clear_entry()
  139.         if new_id:
  140.             if len(new_id) == 18 or new_id == '未录入':
  141.                 clients = self.find()
  142.                 new_clients = []
  143.                 ids = []
  144.                 for client in clients:
  145.                     if client != '\n':
  146.                         if self.username == client.split(',')[3]:
  147.                             new_clients.append(client)
  148.                             ids.append(client.split(',')[2])
  149.                 if new_id in ids:
  150.                     for new_client in new_clients:
  151.                         if new_id == new_client.split(',')[2]:
  152.                             information = '客户姓名:' + new_client.split(',')[0] + '\t' + '客户电话:' + new_client.split(',')[
  153.                                 1] + '\t' + '客户证件号码:' + new_client.split(',')[2] + '\t' + '销售员:' + \
  154.                                           new_client.split(',')[3] + '\t' + '录入时间:' + new_client.split(',')[4]
  155.                             self.text.insert(END, information)
  156.                             break

  157.                 else:
  158.                     showinfo(title='错误', message='未录入此证件号!')
  159.             else:
  160.                 showinfo(title='错误', message='输入非法的证件号!')
  161.         else:
  162.             showinfo(title='错误', message='查询索引不能空!')

  163.     def clear_text(self):
  164.         self.text.delete(0.0, END)

  165.     def clear_entry(self):
  166.         self.name.set('')
  167.         self.phone.set('')
  168.         self.id_nub.set('')
复制代码

最佳答案
2020-8-4 20:34:48
1、打包问题:
   确保代码没问题-->运行dist目录下的exe
如果还有问题,如下重新打包
  1、在目录下新建__init__.py 2、输入打包指令,并指定要导入的第三方库路径,3、打包显示dll缺失,建议恢
   复电脑,重新安装pyinstaller(只重新安装pyinstaller没用,本人亲自遇到)



                               
登录/注册后可看大图


2、调用失败
   因为你的模块名与方法名重复,建议import LoginPage as LP,再在代码里调用LP.LoginPage()
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-4 20:28:14 | 显示全部楼层
重新打包试试
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-4 20:32:00 | 显示全部楼层
注意把杀毒软件关了再试试
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-4 20:34:48 | 显示全部楼层    本楼为最佳答案   
1、打包问题:
   确保代码没问题-->运行dist目录下的exe
如果还有问题,如下重新打包
  1、在目录下新建__init__.py 2、输入打包指令,并指定要导入的第三方库路径,3、打包显示dll缺失,建议恢
   复电脑,重新安装pyinstaller(只重新安装pyinstaller没用,本人亲自遇到)



                               
登录/注册后可看大图


2、调用失败
   因为你的模块名与方法名重复,建议import LoginPage as LP,再在代码里调用LP.LoginPage()
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-5 13:45:25 | 显示全部楼层
1q23w31 发表于 2020-8-4 20:34
1、打包问题:
   确保代码没问题-->运行dist目录下的exe
如果还有问题,如下重新打包

不用这么复杂吧,把360和火绒关了就行了,否则就是代码本身的问题,这个代码太长了,我没仔细看
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-24 23:58

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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