class Pickle(): ''' 二进制文件读取 ''' logger = Logger('Pickle').getlog() def load(self,file_path): ''' 读取二进制文件 :return: ''' try: f = open(file_path, 'rb') file_datas = pickle.load(f) # 读出文件的数据个数 f.close() except Exception as e: self.logger.error('读取二进制文件【%s】失败,无法自动填写账号密码,错误信息:%s'%(file_path,e)) file_datas =False return file_datas def dump(self,obj,path): ''' 写入文件 :param obj: 写入文件的对象 :param path: 路劲 :return: ''' try: f = open(path, 'wb') # 以写模式打开二进制文件 pickle.dump(obj,f) f.close() return True except Exception as e: self.logger.error('写入二进制文件【%s】失败,错误异常:%s' % (path, e)) return False
class WhidowsInfo(): ''' 电脑环境信息 ''' logger = Logger('WhidowsInfo').getlog() def root_coordinate(self,root): ''' 窗口坐标 获取电脑的分辨率,并判断中间位置 :param root: 主窗口控件 :return:返回屏幕中间坐标 ''' ws = root.winfo_screenmmwidth() hs = root.winfo_screenheight() x = (ws/2)+400 y = (hs/2)-250 self.logger.info('当前屏幕分辨率为%sx%s,中间坐标为%s,%s'%(ws,hs,x,y)) return x,y def get_window_time(self): ''' 获取本地时间 :return: ''' now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) # 格式化当前时间 return now
class Str_manager(): logger = Logger('Str_manager').getlog() # 检验字符串是否包含汉字 def check_contain_chinese(self,check_str): ''' 判断传入字符串是否包含中文 :param word: 待判断字符串 :return: None:不包含中文 False:输入的不是字符串 ''' zh_pattern = re.compile(u'[\u4e00-\u9fa5]+') try: match = zh_pattern.search(check_str) return match except: return False
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-02-02 11:20:44 # @Author : Your Name ([email protected]) # @Link : http://example.org # @Version : $Id$ import pymysql from Public.Logger import Logger logger = Logger(logger='Mysql').getlog() class Mysql(): def __init__(self,db_name='test_tmp'): try: self.db = pymysql.connect(host='120.79.152.46', user='******', passwd='123123', db='gui') # 使用cursor()方法获取操作游标 self.cursor = self.db.cursor() logger.info('数据库连接成功...') self.db_state=True except Exception as e: logger.info('数据库连接失败...%s'%e ) self.db_state=False def implement_sql(self,sql): ''' 执行sql :param sql:
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-01-31 18:33:22 # @Author : Your Name ([email protected]) # @Link : http://example.org # @Version : $Id$ import configparser import os from Public.Path_manager import Root_xpath from Public.Logger import Logger logger = Logger(logger='Config').getlog() class Config(): def __init__(self): self.config = configparser.ConfigParser() self.config_xpath = Root_xpath().config_path() + '/' def get_config_data(self, config_name, config_section, config_options): ''' 获取配置文件信息 参数 config_name 配置文件名称 config_title 配置文件组名 config_value 配置文件键名 返回值 False 获取配置文件失败,值为空 values 配置文件信息 '''
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : huxiansheng ([email protected]) import os import tkinter as tk from tkinter import messagebox from PIL import Image, ImageTk from Business.Check import login_check, sign_up_check from Business.Notice import notice from Public.Common import * from Public.Path_manager import Root_xpath from Public.Logger import Logger from Interface.Index import index logger = Logger('login').getlog() class login(): def __init__(self): Remember_statu = '0' # 获取系统路劲 self.root_x = Root_xpath() self.img_xpath = self.root_x.picture_path() self.account_path = self.root_x.config_path() + '/账号.dat' account_info = Pickle().load(self.account_path) # 读取账号密码 # 创建窗体 self.root = tk.Tk() self.root.title('登录') self.root.iconbitmap(self.img_xpath + '/login_title2.ico') self.root.resizable(0, 0) # 阻止Python GUI的大小调整
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : huxiansheng ([email protected]) import tkinter as tk from PIL import Image, ImageTk from Public.Logger import Logger from Public.Path_manager import Root_xpath from Public.Common import * logger = Logger('index').getlog() class index(): def __init__(self): #实例化类 self.root_x = Root_xpath() self.img_xpath = self.root_x.picture_path() #图片存放路劲 #创建窗体 self.index = tk.Tk() self.index.title('古月') self.index.iconbitmap(self.img_xpath + '/login_title2.ico') self.index.resizable(0,0) # 阻止调整窗体大小 self.a, self.b = WhidowsInfo().root_coordinate(self.index) self.index.geometry("830x550+%d+%d" % (self.a, self.b)) #设置窗体大小和位置 # 创建画布 canvas = tk.Canvas(self.index,width=830, height=550, bg='white') image = Image.open(self.img_xpath+'/index_bg.jpg') im = ImageTk.PhotoImage(image) canvas.create_image(348, 250, image=im) # 使用create_image将图片添加到Canvas组件中 canvas.pack() # 将Canvas添加到主窗口