run_mainFrame19.py

该脚本创建了一个GUI界面,用于管理自动化工作流程,包括文件下载、转换、上传和邮件通知。用户选择BU(如PH、KR、SG)、日期和频率,程序将下载相应文件并进行处理。此外,它还包含了文件夹创建、配置文件初始化、日志记录、文件夹监控以及邮件发送等功能。主要涉及的技术有Python的Tkinter、多线程、Excel和邮件处理。
摘要由CSDN通过智能技术生成
# ======================
# imports
# ======================
import tkinter as tk
from tkinter import ttk
from tkinter import scrolledtext
from tkinter import Menu
from tkinter import Spinbox
from tkinter import messagebox as mBox
# import time
import calendar
import threading
import time
import os
import sys
import xlrd
import csv
import codecs
from pathlib import Path
import shutil
import subprocess
#os.path
sys.path.append(Path(__file__).parent.resolve())
sys.path.append(Path(__file__).parent.parent.resolve())
sys.path.append(Path(__file__).parent.parent.parent.resolve())
import win32com.client as win32
# from demo.src.demo.Data_Process import templateFileOutput,finaoutputfilexport,templateFileOutputSgWeekly,templateFileOutputSgDaily,readBrdXlsxForDate
from Data_Process import templateFileOutput,finaoutputfilexport,templateFileOutputSgWeekly,templateFileOutputSgDaily,readBrdXlsxForDate,DoubleFileOfSgToTemplate,templateKRFileOutput,finaoutputfilexportempty,write_to_vacationbuexcel

# import shutil

# from demo.src.testmain import test_upload_files_batch,main,downLoadingMappingTable
datetime = calendar.datetime.datetime
timedelta = calendar.datetime.timedelta

# from demo.src.demo.calendarSelection import Calendar, datepicker
from calendarSelection import Calendar, datepicker
# from demo.test.test_selenium_tool import TestSeleniumTool
# from demo.src.testmain import test_download_files_batch,main,downLoadingMappingTable

from testm_bak import main, download_files_batch, upload_file, download_files_batch_bak, mainforCFA ,upload_fileforCFA

# 由于tkinter中没有ToolTip功能,所以自定义这个功能如下
class ToolTip(object):
    def __init__(self, widget):
        self.widget = widget
        self.tipwindow = None
        self.id = None
        self.x = self.y = 0

    def showtip(self, text):
        "Display text in tooltip window"
        self.text = text
        if self.tipwindow or not self.text:
            return
        x, y, _cx, cy = self.widget.bbox("insert")
        x = x + self.widget.winfo_rootx() + 27
        y = y + cy + self.widget.winfo_rooty() + 27
        self.tipwindow = tw = tk.Toplevel(self.widget)
        tw.wm_overrideredirect(1)
        tw.wm_geometry("+%d+%d" % (x, y))

        label = tk.Label(tw, text=self.text, justify=tk.LEFT,
                         background="#ffffe0", relief=tk.SOLID, borderwidth=1,
                         font=("tahoma", "8", "normal"))
        label.pack(ipadx=1)

    def hidetip(self):
        tw = self.tipwindow
        self.tipwindow = None
        if tw:
            tw.destroy()



# 创建工作文件夹,如果没有就创建;
def mkdir(path):
    # 引入模块
    import os
    # 去除首位空格
    path = path.strip()
    # 去除尾部 \ 符号
    path = path.rstrip("\\")

    # 判断路径是否存在
    # 存在     True
    # 不存在   False
    isExists = os.path.exists(path)
    print(isExists)
    # 判断结果
    if not isExists:
        # 如果不存在则创建目录
        # 创建目录操作函数
        os.makedirs(path)

        print
        path + ' create success!'
        return True
    else:
        # 如果目录存在则不创建,并提示目录已存在
        print
        path + ' dir existed!'
        return False


# mkpath = r"C:\Users\Public\SourceFile"
mkpath = r"C:\Users\Public\SourceFile"
# mkpath1 = r"C:\Users\Public\AdjustmentFile"
mkpath1 = r"C:\Users\Public\AdjustmentFile"
# mkpath11 = r"C:\Users\Public\AdjustmentFile1"
mkpathconfig = r"C:\Users\Public\pythonAutomationConfig"
mkpathlog = r"C:\Users\Public\CashFlowAutomationlog"
# 调用函数
mkdir(mkpath)
mkdir(mkpath1)
mkdir(mkpathconfig)
mkdir(mkpathlog)

if os.path.exists(mkpathconfig) != True:
    os.makedirs(mkpathconfig)
downloadConfig = 'downloadConfig.txt'
mailConfig = 'mailConfig.txt'
uploadConfig = 'uploadConfig.txt'
shareFolderConfig = 'shareFolderConfig.txt'
mailtoConfig = 'mailtoConfig.txt'
mailccConfig = 'mailccConfig.txt'
pageConfig = 'pageConfig.txt'
pageConfig1 = 'pageConfig1.txt'
vacationforbu = 'vacationforbu.xlsx'
dtf = time.strftime("%Y%m%d", time.localtime())
logfile = "CFAlog"+dtf+".log"
# with open(r"C:\Users\Public\SourceFile\pageConfig.txt", "w", encoding='utf-8') as f:
    #     # print("ffn.write:")
    #     f.write('')

downloadConfigpath = os.path.join(mkpathconfig ,downloadConfig)
mailConfigpath = os.path.join(mkpathconfig ,mailConfig)
uploadConfigpath = os.path.join(mkpathconfig ,uploadConfig)
shareFolderConfigpath = os.path.join(mkpathconfig ,shareFolderConfig)
mailtoConfigpath = os.path.join(mkpathconfig,mailtoConfig)
mailccConfigpath = os.path.join(mkpathconfig,mailccConfig)
vacationforbupath = os.path.join(mkpathconfig,vacationforbu)
pageConfigpath = os.path.join(mkpath ,pageConfig)
pageConfigpath1 = os.path.join(mkpath ,pageConfig1)


logfilepath = os.path.join(mkpathlog,logfile)

if os.path.exists(pageConfigpath) != True:
    with open(pageConfigpath, "w", encoding='utf-8') as f:
        f.write("")
if os.path.exists(pageConfigpath1) != True:
    with open(pageConfigpath1, "w", encoding='utf-8') as f:
        f.write("")

if os.path.exists(downloadConfigpath) != True:
    with open(downloadConfigpath, "w", encoding='utf-8') as f:
        f.write("")
        # f.close()

if os.path.exists(mailConfigpath) != True:
    with open(mailConfigpath, "w", encoding='utf-8') as f:
        f.write("")
        # f.close()

if os.path.exists(uploadConfigpath) != True:
    with open(uploadConfigpath, "w", encoding='utf-8') as f:
        f.write("")
        # f.close()

if os.path.exists(shareFolderConfigpath) != True:
    with open(shareFolderConfigpath, "w", encoding='utf-8') as f:
        f.write("")

# print('创建邮件配置config')
if os.path.exists(mailtoConfigpath) != True:
    with open(mailtoConfigpath, "w", encoding='utf-8') as f:
        f.write("")

if os.path.exists(mailccConfigpath) != True:
    with open(mailccConfigpath, "w", encoding='utf-8') as f:
        f.write("")

#create logfile
if os.path.exists(logfilepath) != True:
    with open(mailccConfigpath, "w", encoding='utf-8') as f:
        f.write("")

if os.path.exists(vacationforbupath) != True:
    titleInfo = ['holiday','specialworkday']
    xlsxvacationfobu = 'vacationforbu.xlsx'
    write_to_vacationbuexcel(vacationforbupath,titleInfo)
    print('create vacationforbu.xlsx')

# print("abs path is %s" %(os.path.abspath(sys.argv[0])))
# C:\wz\zep\demo\demo\src\demo\run_mainFrame9.py
patharr = os.path.abspath(sys.argv[0]).split('run_mainFrame')
# print(patharr[0])
# print('os.getcwd():')
# print(os.getcwd())

mkpath1mpt = os.path.join(mkpath1,"Mapping Table.xlsx")

# remove mapping table to folder AdjustmentFile
if os.path.exists(mkpath1mpt) == False:
    #start remove mapping table to folder adjustmentfile
    print('start remove mapping table to folder AdjustmentFile')
    orignalfile =os.path.join(patharr[0],'Mapping Table.xlsx')
    print(orignalfile)
    shutil.copy(orignalfile, mkpath1)



# Create instance
win = tk.Tk()

# Add a title
win.title("Cash Flow File Automation v 0.4")

# Disable resizing the GUI
win.resizable(0, 0)

# Tab Control introduced here --------------------------------------
tabControl = ttk.Notebook(win)  # Create Tab Control

tab1 = ttk.Frame(tabControl)  # Create a tab
tabControl.add(tab1, text='Menu')  # Add the tab

tab2 = ttk.Frame(tabControl)  # Add a second tab
# tabControl.add(tab2, text='Page two')  # Make second tab visible

tab3 = ttk.Frame(tabControl)  # Add a third tab
# tabControl.add(tab3, text='Page three')  # Make second tab visible

tabControl.pack(expand=1, fill="both")  # Pack to make visible
# ~ Tab Control introduced here -----------------------------------------

# ---------------Tab1控件介绍------------------#
# We are creating a container tab3 to hold all other widgets
monty = ttk.LabelFrame(tab1, text='')
monty.grid(column=0, row=0, padx=10, pady=4)

name = tk.StringVar()

ttk.Label(monty, text="   BU:").grid(column=0, row=0, sticky='W')


# 给下拉列表设置点击事件
def go(*args):  # 处理事件,*args表示可变参数
    # print(bookChosen.get()) #打印选中的值
    if bookChosen.get() == 'SG':
        bookChosen1["values"] = ('Daily', 'Weekly')
    else:
        bookChosen1.set('Daily')
        bookChosen1["values"] = ("Daily")


# Adding a Combobox
book = tk.StringVar()
bookChosen = ttk.Combobox(monty, width=12, textvariable=book)
bookChosen['values'] = ('PH', 'KR', 'SG')
bookChosen.grid(column=0, row=1)
bookChosen.current(0)  # 设置初始显示值,值为元组['values']的下标
bookChosen.bind("<<ComboboxSelected>>", go)
bookChosen.config(state='readonly')  # 设为只读模式

ttk.Label(monty, text="   Frequency:").grid(column=2, row=0, sticky='W')
book2 = tk.StringVar()
bookChosen1 = ttk.Combobox(monty, width=12, textvariable=book2)
bookChosen1.set('Daily')
bookChosen1['values'] = ('Daily', 'Weekly')

bookChosen1.grid(column=2, row=1)
bookChosen1.current(0)  # 设置初始显示值,值为元组['values']的下标
bookChosen1.config(state='readonly')  # 设为只读模式

# Using a scrolled Text control
# scrolW = 30;
# scrolH = 5
# scr = scrolledtext.ScrolledText(monty, width=scrolW, height=scrolH, wrap=tk.WORD)
# scr.grid(column=0, row=3, sticky='WE', columnspan=3)

# Add Tooltip

# createToolTip(scr, '这是一个ScrolledText.')

# 一次性控制各控件之间的距离
for child in monty.winfo_children():
    child.grid_configure(padx=2, pady=1)
# 单独控制个别控件之间的距离


# ----------------菜单栏介绍-------------------#
# Exit GUI cleanly
def _quit():
    win.quit()
    win.destroy()
    exit()

# Creating a Menu Bar
menuBar = Menu(win)
win.config(menu=menuBar)


# file donald
def fun():
    # print(bookChosen.get())#获取BU
    # print(nameEntered.get())#获取选择的日期
    # print(bookChosen1.get())#获取下载文件的频率
    # mkpath = r"C:\Users\Public\SourceFile"
    mkpathmp = r"C:\Users\Public\AdjustmentFile" + '\Mapping Table.xlsx'
    # print('mkpathmp:'+mkpathmp)
    # downloadfile = bookChosen.get() + '_' + nameEntered.get() + '.xlsx'
    if bookChosen1.get() == 'Weekly':
        if bookChosen.get() == 'SG':
            downloadfile = bookChosen.get() + '_' + nameEntered.get() + '_Weekly' '.xls'
        else:
            downloadfile = bookChosen.get() + '_' + nameEntered.get() +'_Weekly' '.xlsx'
    else:
        if bookChosen.get() == 'SG':
            downloadfile = bookChosen.get() + '_' + nameEntered.get() + '.xls'
        else:
            downloadfile = bookChosen.get() + '_' + nameEntered.get() + '.xlsx'
    print('downloadfile:' + downloadfile)
    time.sleep(1)
    # if os.path.exists(mkpathmp) != True:
    #     print('download_files_batch_bak')
    #     scr.insert(tk.END, 'download file :' + downloadfile + '\n')
    #     th = threading.Thread(target=download_files_batch_bak(downloadfile))
    #     th.setDaemon(True)  # 守护线程
    #     th.start()
    #     th.join()
    #     print(f'downloadfile: 1{downloadfile}')
    #     time.sleep(0.1)
    #
    #     filepath = r'C:\Users\Public\SourceFile'
    #     filepathname = os.path.join(filepath,downloadfile)
    #     time.sleep(0.1)
    #     print('os.path.exists(filepathname):')
    #     print(os.path.exists(filepathname))
    #     if os.path.exists(filepathname) != True:
    #         #print('获取BU:' + bookChosen.get())  # 获取BU
    #         # print('获取选择的日期:' + nameEntered.get())  # 获取选择的日期
    #         scr.insert(tk.END, 'Cash Flow Adjustment File is Empty\n')
    #         th = threading.Thread(target=finaoutputfilexportempty(downloadfile,nameEntered.get(),bookChosen.get()))
    #
    #     for root, dirs, files in os.walk(mkpath):
    #         for i in files:
    #             if downloadfile + ' ' in i + ' ':  # 这里后面不加一个字母可能会出问题,加上一个(不一定是空格)可以解决99.99%的情况
    #                 scr.insert(tk.END, 'file ' + downloadfile + ' downloaded success!\n')
    #
    # else:
    print('main')
    scr.insert(tk.END, 'Download file :' + downloadfile + '\n')
    th = threading.Thread(target=mainforCFA, args=(downloadfile, r'C:\Users\Public\SourceFile'))
    th.setDaemon(True)  # 守护线程
    th.start()
    th.join()
    print(f'downloadfile: 2  {downloadfile}')
    time.sleep(0.1)

    filepath = r'C:\Users\Public\SourceFile'
    filepathname = os.path.join(filepath, downloadfile)

    if os.path.exists(filepathname) != True:
        #print('获取BU:' + bookChosen.get())  # 获取BU
        # print('获取选择的日期:' + nameEntered.get())  # 获取选择的日期
        scr.insert(tk.END, 'Cash Flow Adjustment File is Empty\n')
        th = threading.Thread(target=finaoutputfilexportempty(downloadfile,nameEntered.get(),bookChosen.get()))
        time.sleep(1)

        #触发邮件
        outlook = win32.Dispatch('outlook.application')
        mail = outlook.CreateItem(0)
        with open(r"C:\Users\Public\pythonAutomationConfig\mailtoConfig.txt", "r", encoding='utf-8') as f:
            mailtoConfig = f.readline()
        with open(r"C:\Users\Public\pythonAutomationConfig\mailccConfig.txt", "r", encoding='utf-8') as f:
            mailccConfig = f.readline()

        with open(r"C:\Users\Public\SourceFile\pageConfig1.txt", "r", encoding='utf-8') as f:
            Emptyfinaloutputfile = f.readline()

        mail.To = mailtoConfig
        mail.CC = mailccConfig

        BU = Emptyfinaloutputfile.split('_')[3]
        print(BU)
        efp = os.path.join(mkpath1, Emptyfinaloutputfile)
        mail.Attachments.Add(efp)
        StrSubject = 'AIA ' + BU + ' Daily Fund Transfer ' + time.strftime("%Y%m%d", time.localtime())
        mail.Subject = StrSubject
        mail.HtmlBody = '<font size = 4>Hi team</font>,<br>' + '<br> <font size = 4>Attached cash adjustment file & Final cash flow output for second level check.<br>' + '<br>Thank you </font>'
        mail.Display(False)


    for root, dirs, files in os.walk(mkpath):
        for i in files:
            if downloadfile + ' ' in i + ' ':  # 这里后面不加一个字母可能会出问题,加上一个(不一定是空格)可以解决99.99%的情况
                scr.insert(tk.END, 'file ' + downloadfile + ' downloaded success!\n')


def get_filename(path, filetype):  # 输入路径、文件类型 例如'.csv'
    name = []
    for root, dirs, files in os.walk(path):
        for i in files:
            if filetype + ' ' in i + ' ':  # 这里后面不加一个字母可能会出问题,加上一个(不一定是空格)可以解决99.99%的情况
                name.append(i)
    return name


# Add another Menu to the Menu Bar and an item
msgMenu = Menu(menuBar, tearoff=0)

# menuBar.add_cascade(label="Message", menu=msgMenu)

# 设置默认日期
# print(time.strftime('%Y-%m-%d'))
date_str = tk.StringVar(value=time.strftime('%Y-%m-%d'))
nameEntered = ttk.Entry(monty, width=12, textvariable=date_str)
nameEntered.grid(column=1, row=1, sticky='W')
nameEntered.config(state='readonly')
date_str_gain = lambda: [date_str.set(date) for date in [Calendar((0, 0)).selection()] if date]

ttk.Button(monty, text='Date', command=date_str_gain).grid(row=0, column=1,sticky='W')



#function for open template File
def rebuilttemplate():
    with open(r"C:\Users\Public\SourceFile\pageConfig.txt", "r", encoding='utf-8') as f:
        finaoutputfile = f.readline()
        # print(finaoutputfile)
    path1 = os.path.join(r"C:\Users\Public\AdjustmentFile",finaoutputfile)
    scr.insert(tk.END, 'Rebuilt template File:' + finaoutputfile + '\n')
    os.startfile(path1)

# 获取选框的值
def get_value():
    print('获取BU:' + bookChosen.get())  # 获取BU
    print('获取选择的日期:' + nameEntered.get())  # 获取选择的日期
    print('获取下载文件的频率:' + bookChosen1.get())  # 获取下载文件的频率


# 获取文件目录的下的xlsx files
def get_items():
    # 'get the new items from folder'
    name = []
    # for root, dirs, files in os.walk(r'C:\wz\SourceFile'):
    for root, dirs, files in os.walk(mkpath):
        for i in files:
            if '.xlsx' + ' ' in i + ' ':  # 这里后面不加一个字母可能会出问题,加上一个(不一定是空格)可以解决99.99%的情况
                name.append(i)
            if '.xls' + ' ' in i + ' ':  # 这里后面不加一个字母可能会出问题,加上一个(不一定是空格)可以解决99.99%的情况
                name.append(i)
    return name


def submit_1():
    # mkpathmp = r"C:\Users\Public\AdjustmentFile" + '\Mapping Table.xlsx'
    result = [var.get() for var in vars if var.get()]
    arr = result[0].split('_')
    print('arr: ')
    print(arr)

    if len(result) == 0:
        scr.insert(tk.END, 'Choose Nothing' + '\n')


    if len(result) == 2 and arr[0] == 'SG':
        print('sg&weekily&daily')
        scr.insert(tk.END, 'Process file:' + result[0] + ' ' + result[1] + '\n')
        th = threading.Thread(target=DoubleFileOfSgToTemplate(result[0],result[1]), args=(result,))
        th.setDaemon(True)  # 守护线程
        th.start()
        with open(r"C:\Users\Public\SourceFile\RecordItems.txt", "w", encoding='utf-8') as f:
            f.write(result[0])
            f.write(" ")
            f.write(result[1])
    if len(result) == 1:
        if arr[0] == 'SG' and len(arr) == 3:
            print('sg&weekily')
            scr.insert(tk.END, 'Process file:' + result[0] + '\n')
            th = threading.Thread(target=templateFileOutputSgWeekly(result[0]), args=(result,))
            th.setDaemon(True)
            th.start()
            with open(r"C:\Users\Public\SourceFile\RecordItems.txt", "w", encoding='utf-8') as f:
                f.write(result[0])
        elif arr[0] == 'SG' and len(arr) == 2:
            scr.insert(tk.END, 'Process file:' + result[0] + '\n')
            th = threading.Thread(target=templateFileOutputSgDaily(result[0]), args=(result,))
            th.setDaemon(True)  # 守护线程
            th.start()
            with open(r"C:\Users\Public\SourceFile\RecordItems.txt", "w", encoding='utf-8') as f:
                f.write(result[0])
        elif arr[0] == 'PH' and len(arr) == 2:
            print('ph')
            print(result[0])
            scr.insert(tk.END, 'Process file:' + result[0] + '\n')
            th = threading.Thread(target=templateFileOutput(result[0]))
            th.setDaemon(True)  # 守护线程
            th.start()
            with open(r"C:\Users\Public\SourceFile\RecordItems.txt", "w", encoding='utf-8') as f:
                f.write(result[0])
        elif arr[0] == 'KR' and len(arr) == 2:
            print('KR')
            print(result[0])
            scr.insert(tk.END, 'Process file:' + result[0] + '\n')
            th = threading.Thread(target=templateKRFileOutput(result[0]))
            th.setDaemon(True)  # 守护线程
            th.start()
            with open(r"C:\Users\Public\SourceFile\RecordItems.txt", "w", encoding='utf-8') as f:
                f.write(result[0])


def submit_2_bak():
    result = [var for var in vars if var]
    print(f"result submit {result}")
    th = threading.Thread(target=templateFileOutput(), args=(result,))
    th.start()

#上传文件
def upload():
    with open(r"C:\Users\Public\SourceFile\pageConfig1.txt", "r", encoding='utf-8') as f:
        finaoutputfile = f.readline()
        print(finaoutputfile)
    # finaoutputfilepath = os.path.join(r"C:\Users\Public\AdjustmentFile",finaoutputfile)
    #
    # workbook = xlrd.open_workbook(finaoutputfilepath)
    # table = workbook.sheet_by_index(0)
    # Cash_Flow_FinalExport_csv = finaoutputfile.split('.')[0]+'.csv'
    scr.insert(tk.END, 'Upload File:'+finaoutputfile+ '\n')
    # finaoutputfilepathcsv = os.path.join(r"C:\Users\Public\AdjustmentFile",Cash_Flow_FinalExport_csv)
    # with codecs.open(finaoutputfilepathcsv, 'w', encoding='utf-8') as f:
    #     write = csv.writer(f)
    #     for row_num in range(table.nrows):
    #         row_value = table.row_values(row_num)
    #         write.writerow(row_value)
    th = threading.Thread(target=upload_fileforCFA(finaoutputfile))
    th.setDaemon(True)  # 守护线程
    th.start()

    #copy file to sharefolder && delete
    orignalfilepath = r'C:\Users\Public\AdjustmentFile'
    orignalfile = os.path.join(orignalfilepath, finaoutputfile)
    # sharefoldertargetpath = 'Q:\IT_Share\CS\Moses\CashFileUpload'

    # mkpathconfig
    # shareFolderConfig

    with open(shareFolderConfigpath, "r", encoding='utf-8') as f:
        sharefoldertargetpath = f.readline()
    print('sharefoldertargetpath:')
    print(sharefoldertargetpath)
    # os.system(r'test.bat ' + orignalfile + ' ' + sharefoldertargetpath)
    scr.insert(tk.END, 'Upload File:' + finaoutputfile + ' to ShareFolder\n')
    os.system('xcopy %s %s /s' % (orignalfile, sharefoldertargetpath))
    scr.insert(tk.END, 'Upload File:' + finaoutputfile + ' Success\n')
    # targetfilepath = r'C:\Users\Public\AdjustmentFile1'
    # print('start to move file')
    # # if os.path.exists(orignalfile) != True:
    # shutil.move(orignalfile, targetfilepath)
    print('删除文件')
    # time.sleep(0.1)
    # os.remove(finaoutputfilepath)
    # os.remove(finaoutputfilepathcsv)
    os.remove(orignalfile)

    #delete BRD sourcefile
    with open(r"C:\Users\Public\SourceFile\RecordItems.txt", "r", encoding='utf-8') as f:
        strItems = f.readline()

    items = strItems.split(' ')
    # print(items)

    for i in range(len(items)):
        filepath = r"C:\Users\Public\SourceFile"
        filepathname = os.path.join(filepath, items[i])
        print('remove:')
        print(filepathname)
        os.remove(filepathname)


def submit_2():
    with open(r"C:\Users\Public\SourceFile\pageConfig.txt", "r", encoding='utf-8') as f:
        Cash_Flow_Template = f.readline()
        # print(Cash_Flow_Template)
    scr.insert(tk.END, 'Export Final File:' + Cash_Flow_Template + '\n')
    th = threading.Thread(target=finaoutputfilexport(Cash_Flow_Template))
    th.setDaemon(True)  # 守护线程
    th.start()
    outlook = win32.Dispatch('outlook.application')
    mail = outlook.CreateItem(0)
    with open(r"C:\Users\Public\SourceFile\pageConfig1.txt", "r", encoding='utf-8') as f:
        ffxlsx = f.readline()
        # print(ffxlsx)
    with open(r"C:\Users\Public\pythonAutomationConfig\mailtoConfig.txt", "r", encoding='utf-8') as f:
        mailtoConfig = f.readline()
    with open(r"C:\Users\Public\pythonAutomationConfig\mailccConfig.txt", "r", encoding='utf-8') as f:
        mailccConfig = f.readline()
    afp = os.path.join(mkpath1,Cash_Flow_Template)
    ffp = os.path.join(mkpath1,ffxlsx)
    mail.To = mailtoConfig
    mail.CC = mailccConfig
    # print(afp)
    # print(ffp)


    BU = Cash_Flow_Template.split('_')[1]

    mail.Attachments.Add(afp)
    mail.Attachments.Add(ffp)
    with open(r"C:\Users\Public\SourceFile\RecordItems.txt", "r", encoding='utf-8') as f:
        sourcefilestr = f.readline()
    sfarr = sourcefilestr.split(' ')
    if len(sfarr) == 1:
        sfarr0path = os.path.join(mkpath,sfarr[0])
        mail.Attachments.Add(sfarr0path)
    if len(sfarr) == 2:
        sfarr0path = os.path.join(mkpath, sfarr[0])
        sfarr1path = os.path.join(mkpath, sfarr[1])
        mail.Attachments.Add(sfarr0path)
        mail.Attachments.Add(sfarr1path)
    # mail.Attachments.Add(mailtoConfig)
    # mail.Attachments.Add(mailccConfig)

    StrSubject ='AIA '+ BU + ' Daily Fund Transfer ' + time.strftime("%Y%m%d", time.localtime())
    mail.Subject = StrSubject
    mail.HtmlBody = '<font size = 4>Hi team</font>,<br>' + '<br> <font size = 4>Attached cash adjustment file & Final cash flow output for second level check.<br>'+ '<br>Thank you </font>'
    mail.Display(False)

# def sendmail():





def submit_2_bak():
    result = [var for var in vars if var]
    # df = [i for i in df if i.get() != '']
    df = [i for i in result if i.get() != '']
    for x in df:
        print('item:')
        print(x.get())
    print(f"result submit {result}")
    th = threading.Thread(target=templateFileOutput(), args=(result,))
    th.start()


def next(df):
    print(f"df {df} start")
    import time
    df = [i for i in df if i.get() != '']
    for x in df:
        print('item:')
        print(x.get())
    time.sleep(10)
    # print(f"df {df} end")


def show_items():
    hobby_list = get_items()
    # print(hobby_list)

    for i in range(len(hobby_list)):
        rollnum = hobby_list[i]
        if rollnum not in re_list:
            var = tk.StringVar(value=rollnum)
            cb = tk.Checkbutton(text, text=rollnum, variable=var, onvalue=rollnum, offvalue='', bg='white', command='')
            text.window_create('end', window=cb)
            text.insert('end', '\n')
            vars.append(var)

            re_list.append(rollnum)


frame = tk.Frame(win)
frame.pack()

xlist = []
vars = []
re_list = []

# action = ttk.Button(monty, text="submmit", width=10, command=getValue)
# getValue
action = ttk.Button(monty, text="Download", width=9, command=fun)
action.grid(column=3, row=1, rowspan=1, ipady=1.2)

show_items = tk.Button(monty, text="ShowItems", width=9, command=show_items)
show_items.grid(column=3, row=3, rowspan=1, ipady=1.2)

Submit = tk.Button(monty, text="Submit ", width=9, command=submit_1)
Submit.grid(column=3, row=4, rowspan=1,ipady=1.2)

Rebuilt = tk.Button(monty, text="Rebuilt ", width=9, command=rebuilttemplate)
Rebuilt.grid(column=3, row=5, rowspan=1,ipady=1.2)

Review = tk.Button(monty, text="Review ", width=9, command=submit_2)
Review.grid(column=3, row=8, rowspan=1,ipady=1.2)

Upload = tk.Button(monty, text="Upload ", width=9, command=upload)
Upload.grid(column=3, row=9, rowspan=1,ipady=1.2)

Exit = tk.Button(monty, text="Exit ", width=9, command=_quit)
Exit.grid(column=3, row=11, rowspan=1,ipady=1.2)
# tk.Button(win, text='Submit', command=submit).pack(side=tk.LEFT)
# tk.Button(win, text='Review', command=submit_2).pack()  # 生成final outputfile
# tk.Button(win, text='Upload', command=upload).pack(side=tk.RIGHT)
# tk.Button(win, text='Upload', command=upload).pack(side=tk.LEFT)
# text = tk.Text(frame, width=30, height=10)

text = tk.Text(monty, width=26, height=11)
# text.pack(side=tk.LEFT, fill=tk.BOTH)
text.grid(column=0, row=2,rowspan=6,sticky='WE', columnspan=3)
# vsb = tk.Scrollbar(frame, orient=tk.VERTICAL, command=text.yview)
# vsb.pack(side=tk.LEFT, fill=tk.Y)
# text.config(yscrollcommand=vsb.set)

#界面布局
scrolW = 35
scrolH = 11
scr = scrolledtext.ScrolledText(monty, width=scrolW, height=scrolH, wrap=tk.WORD)
scr.grid(column=0, row=8,rowspan=4, sticky='WE', columnspan=3)
win.mainloop()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值