Python&;Tkinter:解析Tkinter scrolledtext中的文本,并获取用于运行定义的按钮,该定义开始解析过程

Python&;Tkinter:解析Tkinter scrolledtext中的文本,并获取用于运行定义的按钮,该定义开始解析过程,python,tkinter,global-variables,text-parsing,local-variables,Python,Tkinter,Global Variables,Text Parsing,Local Variables,我目前有一个工作脚本,可以解析文本文件中的文本数据 我感兴趣的不是使用文本文件,而是使用Tkinter Scrolled文本来保存数据,而不是使用文本文件。然后我希望有一个Tkinter按钮,它将运行解析函数并解析数据,就像我使用文本文件中的数据运行解析脚本时通常所做的那样 当我试图通过tkinter按钮将工作脚本转换为运行的定义时,我遇到了局部变量和全局变量的问题。作为一个简单的修复,我将工作脚本直接添加到包含tkinter代码的新代码中。然后将工作脚本设置为一个循环,当按下tkinter按钮

我目前有一个工作脚本,可以解析文本文件中的文本数据

我感兴趣的不是使用文本文件,而是使用Tkinter Scrolled文本来保存数据,而不是使用文本文件。然后我希望有一个Tkinter按钮,它将运行解析函数并解析数据,就像我使用文本文件中的数据运行解析脚本时通常所做的那样

当我试图通过tkinter按钮将工作脚本转换为运行的定义时,我遇到了局部变量和全局变量的问题。作为一个简单的修复,我将工作脚本直接添加到包含tkinter代码的新代码中。然后将工作脚本设置为一个循环,当按下tkinter按钮时,该循环将被激活,该按钮称为一个新的定义,该定义只是更改了布尔值。假定更改后的布尔值使工作脚本运行

我原以为这样行得通,但事实并非如此。如果有人能(1)帮助我理解如何正确运行我的工作脚本作为通过tkinter按钮调用的定义,或者(2)帮助我修复我的“修复”,其中工作脚本没有转换为定义,而是保存在一个循环中,我将非常感激

请参阅下面的脚本“简单修复”版本:(请参阅下面的@Mike-SMT帖子了解当前脚本-我通过了单词限制,试图将旧脚本和newtestable.txt文件添加到此帖子中)

下面是一个可测试的.txt文件。(更新)


这里发生了很多事情,很多事情需要改变

  • 在关闭应用程序之前,
    mainloop()
    之后的代码不会工作。因此,让我们将解析代码移动到用于更新onWork的函数中

  • 可以使用循环生成大多数标签和输入字段。这将有助于减少行数,使内容更易于阅读。通过输入字段列表,您可以使用列表+索引值来获取所需内容

  • 您有很多代码没有执行任何操作或从未被调用。我已经从示例中删除了所有这些内容

  • oneCountries
    可能应该是您导入的单独文件中的列表。如果您遵循PEP8行长度规则,那么最终会在代码中添加一堆行

  • 除了一些小事情外,我对您的解析代码没有太大的更改,因为我没有任何数据要测试,所以我无法按原样编写更好的版本。也就是说,我可以看到很多地方会出问题。如果你的情况有问题。例如,您使用循环值
    line
    运行一个循环,然后使用相同值
    line
    运行子循环,这将导致在到达下一个if之前覆盖内容。或者,如果
    if
    语句失败,则您没有else条件,因此在没有定义这些变量的情况下,代码的其余部分可能会失败。因此,如果您可以提供一些示例文件数据,我可以更新该部分

  • 您有几个未使用的导入项。尽量保持你的文章简洁明了

  • 删除所有未使用的代码并重新编写其他代码后,示例从320行增加到140+。 下面是经过修改的代码。如果您有任何问题,请告诉我:

    import tkinter as tk
    from tkinter import scrolledtext
    from itertools import islice
    import re
    
    
    def click_work():
        print('clicked!!')
        print('do work is now in the function!!')
        the_file = txt1.get('1.0', 'end-1c').split('\n')
        print(the_file)
        for line in the_file:
            line = line.strip()
            # print(line)
            if re.match(r'Blah-2020'.upper(), line.upper()):
                print('the_id', line)
                the_id = line  # had to rename due to "id" being a built in function.
            if re.match(r'Submitted: ', line):
                date = line
                for line1 in islice(the_file, 2):
                    title = line1
                for line2 in islice(the_file, 3):
                    authors = line2
                for line3 in islice(the_file, 3):
                    ms_type = line3
                for line4 in islice(the_file, 3):
                    extra_data = line4
    
            if line.startswith('Submitting Author:'):
                country_parsing = True
            elif line.startswith('Running Head:'):
                country_parsing = False
            else:
                country_parsing = False
    
            print(country_parsing)
            if country_parsing:
                for d in countries:
                    if d in line:
                        my_other_list.append(d)
    
            if line.startswith('Author\'s Cover Letter:'):
                cover_letter_parsing = True
            elif line.startswith('If you have been invited to submit an article for a supplement, '
                                 'please select the title of the supplement:'):
                cover_letter_parsing = False
            else:
                cover_letter_parsing = False
    
            if cover_letter_parsing:
                cover_letter.append(line)
    
            if re.match(r'Discipline:', line):
                for sub_line in islice(the_file, 2):
                    discipline = sub_line
            # print(line)
            # print(r'Overall Similarity Index Percentage:' in line)
            if r'Overall Similarity Index Percentage:' in line:
                ithenticate = line
    
        # note several lines will error if a condition was not met previously.
        # so if I were you I would write in some default values just in case match fails.
        ithenticate = float(re.sub('%', '', ithenticate.split(':')[1])) / 100
        first_author = authors.split(',')[0]
        date = date.split(':')[1].split(';')[0].strip(' ')
        id_short = re.sub('Blah'.upper(), '', the_id.upper())
        countries_without_duplicates = list(dict.fromkeys(my_other_list))
        cover_letter.pop(0)
        countrry = ', '.join(countries_without_duplicates)
    
        results = [authors, first_author, the_id, date, ms_type, discipline, ithenticate,
                   id_short, extra_data, my_other_list[0], my_other_list[-1], countrry]
    
        for ndex, entry in enumerate(entry_list3):
            if ndex < len(results):
                entry.delete(0, 'end')
                entry.insert(0, results[ndex])
    
        print("@@@@@@@@@@\n@@@@@@@@@@\n@@@@@@@@@@\n")
        print("All Authors: " + authors)
        print("First Author: " + first_author)
        print("\nMS ID: " + the_id)
        print("\nMS Title: " + title)
        print("Submission date: " + date)
        print("MS type: " + ms_type)
        print("Discipline: " + discipline)
        print("iThenticate: " + str(ithenticate))
        print("MS ID (short version): " + id_short)
        print("Extra info: " + extra_data)
        print("First Author's Country: " + my_other_list[0])
        print("Last  Author's Country: " + my_other_list[-1])
        print("All Author's Countries (w/o duplicates): " + countrry)
    
    oneCountries = "Afghanistan, Albania, Algeria, Andorra, Angola, Antigua & Deps, Argentina, Armenia, Australia, Austria, Azerbaijan, Bahamas, Bahrain, Bangladesh, Barbados, Belarus, Belgium, Belize, Benin, Bhutan, Bolivia, Bosnia Herzegovina, Botswana, Brazil, Brunei, Bulgaria, Burkina, Burma, Burundi, Cambodia, Cameroon, Canada, Cape Verde, Central African Rep, Chad, Chile, China, Republic of China, Colombia, Comoros, Democratic Republic of the Congo, Republic of the Congo, Costa Rica, Côte d’Ivoire, Ivory Coast, Republic of Côte d'Ivoire, Croatia, Cuba, Cyprus, Czech Republic, Danzig, Denmark, Djibouti, Dominica, Dominican Republic, East Timor, Ecuador, Egypt, El Salvador, Equatorial Guinea, Eritrea, Estonia, Ethiopia, Fiji, Finland, France, Gabon, Gaza Strip, The Gambia, Georgia, Germany, Ghana, Greece, Grenada, Guatemala, Guinea, Guinea-Bissau, Guyana, Haiti, Holy Roman Empire, Honduras, Hungary, Iceland, India, Indonesia, Iran, Iraq, Republic of Ireland, Israel, Italy, Ivory Coast, Jamaica, Japan, Jonathanland, Jordan, Kazakhstan, Kenya, Kiribati, North Korea, South Korea, Kosovo, Kuwait, Kyrgyzstan, Laos, Latvia, Lebanon, Lesotho, Liberia, Libya, Liechtenstein, Lithuania, Luxembourg, Macedonia, Madagascar, Malawi, Malaysia, Maldives, Mali, Malta, Marshall Islands, Mauritania, Mauritius, Mexico, Micronesia, Moldova, Monaco, Mongolia, Montenegro, Morocco, Mount Athos, Mozambique, Namibia, Nauru, Nepal, Newfoundland, Netherlands, New Zealand, Nicaragua, Niger, Nigeria, Norway, Oman, Ottoman Empire, Pakistan, Palau, Panama, Papua New Guinea, Paraguay, Peru, Philippines, Poland, Portugal, Prussia, Qatar, Romania, Rome, Russian Federation, Rwanda, St Kitts & Nevis, St Lucia, Saint Vincent & the Grenadines, Samoa, San Marino, Sao Tome & Principe, Saudi Arabia, Senegal, Serbia, Seychelles, Sierra Leone, Singapore, Slovakia, Slovenia, Solomon Islands, Somalia, South Africa, Spain, Sri Lanka, Sudan, Suriname, Swaziland, Sweden, Switzerland, Syria, Tajikistan, Tanzania, Thailand, Togo, Tonga, Trinidad & Tobago, Tunisia, Turkey, Turkmenistan, Tuvalu, Uganda, Ukraine, United Arab Emirates, United Kingdom, United States, Uruguay, Uzbekistan, Vanuatu, Vatican City, Venezuela, Vietnam, Yemen, Zambia, Zimbabwe"
    
    lbl_list = ['Authors: ', '1st Author: ', 'MS ID: ', 'MS Title: ', 'Sub. Date: ',
                'MS Type: ', 'Discipline: ', 'iThenticate: ', 'Extra Info: ',
                '1st Au Country: ', 'Last Au Country: ', 'All Au Country: ', 'COI parameters: ']
    
    window = tk.Tk()
    window.geometry('225x225')
    window.title('Title Here')
    entry_list1 = []  # you can use these list to get the data from entry fields
    entry_list2 = []  # you can use these list to get the data from entry fields
    entry_list3 = []  # you can use these list to get the data from entry fields
    bool_list = []   # you can use this list to get the data from bool vars
    
    tk.Label(window, text='Add Copy&Paste text here', font=('Arial Bold', 10)).grid(column=0, row=0, sticky='w')
    txt1 = scrolledtext.ScrolledText(window, height=0, width=25)
    txt1.grid(column=0, row=1)
    txt1.insert('insert', 'Paste the text here...')
    
    tk.Button(window, text='Analyze the text', bg='white', fg='green',
              command=click_work).grid(column=0, row=4, sticky='w')
    
    tk.Label(window, text='Did you download the files yet?').grid(column=0, row=5, sticky='w')
    rad1 = tk.Radiobutton(window, text='yes', value=1)
    rad2 = tk.Radiobutton(window, text='no', value=0)
    rad1.grid(column=0, row=6, sticky='w')
    rad2.grid(column=0, row=6)
    
    tk.Label(window, text='Files:').grid(column=0, row=8, sticky='w')
    
    
    for i in range(9, 15):
        tk.Label(window, text='{})'.format(i)).grid(column=0, row=9, sticky='w')
        entry_list1.append(tk.Entry(window, width=25, state='disabled'))
        entry_list1[-1].grid(column=0, row=i)
        tk.Label(window, text='~~>', font=('Arial Bold', 10)).grid(column=0, row=i, sticky='e')
        entry_list2.append(tk.Entry(window, width=25))
        entry_list2[-1].grid(column=1, row=i, sticky='w')
        bool_list.append(tk.BooleanVar())
        bool_list[-1].set(True)
        tk.Checkbutton(window, var=bool_list[-1]).grid(column=1, row=9, sticky='e')
    
    for ndex, value in enumerate(lbl_list):
        if ndex == 0:
            sticky1 = 'se'
            sticky2 = 's'
        else:
            sticky1 = 'ne'
            sticky2 = 'n'
        tk.Label(window, text=value).grid(column=2, row=ndex+1, sticky=sticky1)
        entry_list3.append(tk.Entry(window, width=55))
        entry_list3[-1].grid(column=3, row=ndex+1, sticky=sticky2)
        bool_list.append(tk.BooleanVar())
        bool_list[-1].set(True)
        tk.Checkbutton(window, var=bool_list[-1]).grid(column=4, row=ndex+1, sticky=sticky2)
    
    cb_list = ['Title Page', 'Abstract', 'Ethics', 'Consent', 'Contribution', 'COI', 'Funding', 'Cover Letter']
    for ndex, value in enumerate(cb_list):
        tk.Checkbutton(window, text=value).grid(column=0, row=ndex+16, sticky='w')
    
    countries = oneCountries.split(', ')
    my_other_list = []
    directory = 'C:/Users/me/Desktop/'
    path = 'C:/Users/me/Desktop/read.txt'
    cover_letter = []
    window.mainloop()
    
    将tkinter作为tk导入
    从tkinter导入滚动文本
    从itertools导入islice
    进口稀土
    def单击工作()
    打印('单击!!')
    print('do work现在在函数中!!')
    _文件=txt1.get('1.0','end-1c').split('\n'))
    打印(_文件)
    对于_文件中的行:
    line=line.strip()
    #打印(行)
    如果重新匹配(r'Blah-2020'.upper(),line.upper()):
    打印('u id',行)
    _id=line#必须重命名,因为“id”是一个内置函数。
    如果重新匹配(r'Submitted:',第行):
    日期=行
    对于islice中的第1行(_文件,2):
    标题=第1行
    对于islice中的第2行(_文件,3):
    作者=第2行
    对于islice中的第3行(_文件,3):
    ms_类型=第3行
    对于islice中的第4行(_文件,3):
    额外数据=第4行
    如果line.startswith('提交作者:'):
    国家/地区=True
    elif line.startswith('Running Head:'):
    国家/地区=错误
    其他:
    国家/地区=错误
    打印(国家/地区)
    如果国家/地区:
    对于d国:
    如果d在直线上:
    我的其他列表。附加(d)
    如果line.startswith('作者的求职信:'):
    封面字母解析=真
    elif line.startswith('如果您被邀请提交一篇文章作为补充,'
    '请选择副刊的标题:'):
    封面字母解析=假
    其他:
    封面字母解析=假
    如果封面字母解析:
    封面信。附加(行)
    如果重新匹配(r‘规程:’,第行):
    对于islice中的子_行(_文件,2):
    专业=次级线
    #打印(行)
    #打印(r'总体相似性指数百分比:'行内)
    如果r'总体相似性指数百分比:'在同一行:
    ithenticate=直线
    #注:如果之前未满足某个条件,则会出现多行错误。
    #所以如果我是你们,我会写一些默认值,以防匹配失败。
    ithenticate=float(re.sub(“%”,“,”,ithenticate.split(“:”)[1])/100
    first_author=authors.split(',')[0]
    日期=日期。拆分(“:”)[1]。拆分(“;”)[0]。拆分(“”)
    id_short=re.sub('Blah.upper(),'',the_id.upper())
    没有重复项的国家/地区=列表(dict.fromkeys(我的其他列表))
    封面字母pop(0)
    countrry=','。加入(没有重复项的国家/地区)
    结果=[作者,第一作者,
    
    import tkinter as tk
    from tkinter import scrolledtext
    from itertools import islice
    import re
    
    
    def click_work():
        print('clicked!!')
        print('do work is now in the function!!')
        the_file = txt1.get('1.0', 'end-1c').split('\n')
        print(the_file)
        for line in the_file:
            line = line.strip()
            # print(line)
            if re.match(r'Blah-2020'.upper(), line.upper()):
                print('the_id', line)
                the_id = line  # had to rename due to "id" being a built in function.
            if re.match(r'Submitted: ', line):
                date = line
                for line1 in islice(the_file, 2):
                    title = line1
                for line2 in islice(the_file, 3):
                    authors = line2
                for line3 in islice(the_file, 3):
                    ms_type = line3
                for line4 in islice(the_file, 3):
                    extra_data = line4
    
            if line.startswith('Submitting Author:'):
                country_parsing = True
            elif line.startswith('Running Head:'):
                country_parsing = False
            else:
                country_parsing = False
    
            print(country_parsing)
            if country_parsing:
                for d in countries:
                    if d in line:
                        my_other_list.append(d)
    
            if line.startswith('Author\'s Cover Letter:'):
                cover_letter_parsing = True
            elif line.startswith('If you have been invited to submit an article for a supplement, '
                                 'please select the title of the supplement:'):
                cover_letter_parsing = False
            else:
                cover_letter_parsing = False
    
            if cover_letter_parsing:
                cover_letter.append(line)
    
            if re.match(r'Discipline:', line):
                for sub_line in islice(the_file, 2):
                    discipline = sub_line
            # print(line)
            # print(r'Overall Similarity Index Percentage:' in line)
            if r'Overall Similarity Index Percentage:' in line:
                ithenticate = line
    
        # note several lines will error if a condition was not met previously.
        # so if I were you I would write in some default values just in case match fails.
        ithenticate = float(re.sub('%', '', ithenticate.split(':')[1])) / 100
        first_author = authors.split(',')[0]
        date = date.split(':')[1].split(';')[0].strip(' ')
        id_short = re.sub('Blah'.upper(), '', the_id.upper())
        countries_without_duplicates = list(dict.fromkeys(my_other_list))
        cover_letter.pop(0)
        countrry = ', '.join(countries_without_duplicates)
    
        results = [authors, first_author, the_id, date, ms_type, discipline, ithenticate,
                   id_short, extra_data, my_other_list[0], my_other_list[-1], countrry]
    
        for ndex, entry in enumerate(entry_list3):
            if ndex < len(results):
                entry.delete(0, 'end')
                entry.insert(0, results[ndex])
    
        print("@@@@@@@@@@\n@@@@@@@@@@\n@@@@@@@@@@\n")
        print("All Authors: " + authors)
        print("First Author: " + first_author)
        print("\nMS ID: " + the_id)
        print("\nMS Title: " + title)
        print("Submission date: " + date)
        print("MS type: " + ms_type)
        print("Discipline: " + discipline)
        print("iThenticate: " + str(ithenticate))
        print("MS ID (short version): " + id_short)
        print("Extra info: " + extra_data)
        print("First Author's Country: " + my_other_list[0])
        print("Last  Author's Country: " + my_other_list[-1])
        print("All Author's Countries (w/o duplicates): " + countrry)
    
    oneCountries = "Afghanistan, Albania, Algeria, Andorra, Angola, Antigua & Deps, Argentina, Armenia, Australia, Austria, Azerbaijan, Bahamas, Bahrain, Bangladesh, Barbados, Belarus, Belgium, Belize, Benin, Bhutan, Bolivia, Bosnia Herzegovina, Botswana, Brazil, Brunei, Bulgaria, Burkina, Burma, Burundi, Cambodia, Cameroon, Canada, Cape Verde, Central African Rep, Chad, Chile, China, Republic of China, Colombia, Comoros, Democratic Republic of the Congo, Republic of the Congo, Costa Rica, Côte d’Ivoire, Ivory Coast, Republic of Côte d'Ivoire, Croatia, Cuba, Cyprus, Czech Republic, Danzig, Denmark, Djibouti, Dominica, Dominican Republic, East Timor, Ecuador, Egypt, El Salvador, Equatorial Guinea, Eritrea, Estonia, Ethiopia, Fiji, Finland, France, Gabon, Gaza Strip, The Gambia, Georgia, Germany, Ghana, Greece, Grenada, Guatemala, Guinea, Guinea-Bissau, Guyana, Haiti, Holy Roman Empire, Honduras, Hungary, Iceland, India, Indonesia, Iran, Iraq, Republic of Ireland, Israel, Italy, Ivory Coast, Jamaica, Japan, Jonathanland, Jordan, Kazakhstan, Kenya, Kiribati, North Korea, South Korea, Kosovo, Kuwait, Kyrgyzstan, Laos, Latvia, Lebanon, Lesotho, Liberia, Libya, Liechtenstein, Lithuania, Luxembourg, Macedonia, Madagascar, Malawi, Malaysia, Maldives, Mali, Malta, Marshall Islands, Mauritania, Mauritius, Mexico, Micronesia, Moldova, Monaco, Mongolia, Montenegro, Morocco, Mount Athos, Mozambique, Namibia, Nauru, Nepal, Newfoundland, Netherlands, New Zealand, Nicaragua, Niger, Nigeria, Norway, Oman, Ottoman Empire, Pakistan, Palau, Panama, Papua New Guinea, Paraguay, Peru, Philippines, Poland, Portugal, Prussia, Qatar, Romania, Rome, Russian Federation, Rwanda, St Kitts & Nevis, St Lucia, Saint Vincent & the Grenadines, Samoa, San Marino, Sao Tome & Principe, Saudi Arabia, Senegal, Serbia, Seychelles, Sierra Leone, Singapore, Slovakia, Slovenia, Solomon Islands, Somalia, South Africa, Spain, Sri Lanka, Sudan, Suriname, Swaziland, Sweden, Switzerland, Syria, Tajikistan, Tanzania, Thailand, Togo, Tonga, Trinidad & Tobago, Tunisia, Turkey, Turkmenistan, Tuvalu, Uganda, Ukraine, United Arab Emirates, United Kingdom, United States, Uruguay, Uzbekistan, Vanuatu, Vatican City, Venezuela, Vietnam, Yemen, Zambia, Zimbabwe"
    
    lbl_list = ['Authors: ', '1st Author: ', 'MS ID: ', 'MS Title: ', 'Sub. Date: ',
                'MS Type: ', 'Discipline: ', 'iThenticate: ', 'Extra Info: ',
                '1st Au Country: ', 'Last Au Country: ', 'All Au Country: ', 'COI parameters: ']
    
    window = tk.Tk()
    window.geometry('225x225')
    window.title('Title Here')
    entry_list1 = []  # you can use these list to get the data from entry fields
    entry_list2 = []  # you can use these list to get the data from entry fields
    entry_list3 = []  # you can use these list to get the data from entry fields
    bool_list = []   # you can use this list to get the data from bool vars
    
    tk.Label(window, text='Add Copy&Paste text here', font=('Arial Bold', 10)).grid(column=0, row=0, sticky='w')
    txt1 = scrolledtext.ScrolledText(window, height=0, width=25)
    txt1.grid(column=0, row=1)
    txt1.insert('insert', 'Paste the text here...')
    
    tk.Button(window, text='Analyze the text', bg='white', fg='green',
              command=click_work).grid(column=0, row=4, sticky='w')
    
    tk.Label(window, text='Did you download the files yet?').grid(column=0, row=5, sticky='w')
    rad1 = tk.Radiobutton(window, text='yes', value=1)
    rad2 = tk.Radiobutton(window, text='no', value=0)
    rad1.grid(column=0, row=6, sticky='w')
    rad2.grid(column=0, row=6)
    
    tk.Label(window, text='Files:').grid(column=0, row=8, sticky='w')
    
    
    for i in range(9, 15):
        tk.Label(window, text='{})'.format(i)).grid(column=0, row=9, sticky='w')
        entry_list1.append(tk.Entry(window, width=25, state='disabled'))
        entry_list1[-1].grid(column=0, row=i)
        tk.Label(window, text='~~>', font=('Arial Bold', 10)).grid(column=0, row=i, sticky='e')
        entry_list2.append(tk.Entry(window, width=25))
        entry_list2[-1].grid(column=1, row=i, sticky='w')
        bool_list.append(tk.BooleanVar())
        bool_list[-1].set(True)
        tk.Checkbutton(window, var=bool_list[-1]).grid(column=1, row=9, sticky='e')
    
    for ndex, value in enumerate(lbl_list):
        if ndex == 0:
            sticky1 = 'se'
            sticky2 = 's'
        else:
            sticky1 = 'ne'
            sticky2 = 'n'
        tk.Label(window, text=value).grid(column=2, row=ndex+1, sticky=sticky1)
        entry_list3.append(tk.Entry(window, width=55))
        entry_list3[-1].grid(column=3, row=ndex+1, sticky=sticky2)
        bool_list.append(tk.BooleanVar())
        bool_list[-1].set(True)
        tk.Checkbutton(window, var=bool_list[-1]).grid(column=4, row=ndex+1, sticky=sticky2)
    
    cb_list = ['Title Page', 'Abstract', 'Ethics', 'Consent', 'Contribution', 'COI', 'Funding', 'Cover Letter']
    for ndex, value in enumerate(cb_list):
        tk.Checkbutton(window, text=value).grid(column=0, row=ndex+16, sticky='w')
    
    countries = oneCountries.split(', ')
    my_other_list = []
    directory = 'C:/Users/me/Desktop/'
    path = 'C:/Users/me/Desktop/read.txt'
    cover_letter = []
    window.mainloop()