telephone文件(主文件)
"""
界面的执行文件
"""
import tkinter as tk
from tkinter import ttk
from Telephone.data.t_data_handle import Handle
class fMain():
def __init__(self):
self.ph = Handle()
def pro_handle(self, pro_set, t_output_num, window):
self.ph.data_handle(pro_set, t_output_num, window)
def createMain(self, window):
# 设置窗口的标题
self.window = window
window.title("电话号码下载")
# 设定是否能够改变窗口大小的尺寸
window.resizable(True, True)
# 设置窗口背景颜色(#F5F5DC米色)
window['bg'] = "#F5F5DC"
# 获取屏幕宽度和高度
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
# 计算窗口在屏幕中间位置坐标
x = (screen_width - 800) // 2
y = (screen_height - 500) // 2
# 设置窗口在屏幕中间位置
window.geometry("800x500+{}+{}".format(x, y))
# 创建文本标签
l_input_num = tk.Label(window, text="Telephone Number", font=28, bg="#F5F5DC")
l_input_num.place(relx=0.14, rely=0.08)
l_output_num = tk.Label(window, text="Load Telephone", font=28, bg="#F5F5DC")
l_output_num.place(relx=0.7, rely=0.08)
l_pro_num = tk.Label(window, text="进度条:", font=28, bg="#F5F5DC")
l_pro_num.place(relx=0.04, rely=0.84)
# 创建文本输入框
t_input_num = tk.Text(window, width=35, height=20, font=28, relief="groove")
t_input_num.place(relx=0.05, rely=0.13)
self.ph.input_msg(t_input_num)
t_output_num = tk.Text(window, width=35, height=20, font=28, relief="groove")
t_output_num.place(relx=0.6, rely=0.13)
# 创建进度条
pro_set = tk.ttk.Progressbar(window, length=670, mode='determinate', orient=tk.HORIZONTAL)
pro_set.place(relx=0.12, rely=0.84)
# 创建按钮
# 使用lambda表达式实现command命令中函数的传参
b_active = tk.Button(window, text="执行", height=3, width=10, font=28,
command=lambda: self.pro_handle(pro_set, t_output_num, window))
b_active.place(relx=0.44, rely=0.4)
if __name__ == '__main__':
fm = fMain()
window = tk.Tk()
fm.createMain(window)
window.mainloop()
数据库处理文件
sqlConnect和sqlHandle
"""
数据库的连接
"""
import sys
import datetime
import chardet
import cx_Oracle as ora
from datetime import datetime
from chardet import UniversalDetector
import Telephone.common.const.t_ora_db as tod
class dbHelper(object):
def __init__(self, dt=tod.postgresqlDBT):
self.__dbType = None
self.passwd = ""
self.con = self._getDatabaseConn(dt)
self.cursor = self.con.cursor()
def close(self):
self.cursor.close()
self.con.close()
self.__connName = ""
def _getDatabaseConn(self, dt):
if dt == tod.lacsDB:
dbConn = ora.connect(tod.oracle_lacs_db_user_name, tod.oracle_lacs_db_pass_word, tod.oracle_lacs_db)
self.__dbType = 0
return dbConn
def queryScalar(self, sql, *params):
"""
返回一行第一列
:param sql:
:param params:
:return: 返回一行第一列
"""
self.cursor.execute(sql, params)
row = self.cursor.fetchone()
if row is not None:
return row[0]
else:
return None
def queryAll(self, sql):
"""
返回所有記錄
:param sql:
:return: 返回表的所有數據,list of tuple,[('aa',bb'),('cc','dd'),('ee','ff')]
"""
try:
self.cursor.execute(sql)
result = self.cursor.fetchall()
except Exception as e:
print(e)
raise
return result
def commit(self):
self.con.commit()
def getDbType(self):
return self.__dbType
"""
数据库的处理
"""
import Telephone.sql.t_sql as ts
class sqlDel(object):
def getPageList(self, dbCon):
sql = ts.sql01[dbCon.getDbType()]
# 返回所有記錄
data = dbCon.queryAll(sql)
return data
数据处理
"""
窗口数据处理
"""
import time
from Telephone.sql.sqlHandle.t_sql_handle import sqlDel
from Telephone.sql.sqlConnect.t_sql_connect import dbHelper
class Handle(object):
def data_rows(self):
rows = []
dbCon = dbHelper(100000)
sd = sqlDel()
try:
rows = sd.getPageList(dbCon)
except Exception as e:
print(e)
finally:
dbCon.close()
del dbCon
data = []
for r in rows:
data.append(r[0])
return data
# 第一个输入框里面显示的内容
def input_msg(self, t_input_num):
data = self.data_rows()
for i in range(0, len(data)):
t_input_num.insert("insert", data[i])
t_input_num.insert("insert", '\n')
# 按钮执行的命令后显示的结果
def data_handle(self, pro_set, t_output_num, window):
data = self.data_rows()
pro_set['value'] = 0
step = int(100 / len(data) + 1)
for i in range(0, len(data)):
pro_set['value'] += step
t_output_num.insert("insert", data[i])
# 更新UI确保进度条的变化立即反映出来
window.update_idletasks()
time.sleep(1)
t_output_num.insert("insert", '\n')
常量定义
t_ora_db
"""
oracle的数据连接参数
"""
# 测试的数据库
lacsDB = 100000
oracle_lacs_db = "LACSDB01"
oracle_lacs_db_user_name = "sfcs"
oracle_lacs_db_pass_word = "efactory123"
postgresqlDBT = 300000
标签:功能,self,window,num,def,import,电话簿,data,下载 From: https://blog.csdn.net/weixin_58573288/article/details/140668387感谢学习和参考,关注不迷路!!!