Python 3 Tkinker多线程

时间:2016-06-23 14:05:24

标签: python multithreading python-3.x tkinter

我已经厌倦了为我的基本tkinker搜索GUI实现其他线程,但是,在我尝试的各种实现中,没有一个为我工作。搜索功能需要一些时间来搜索所有目录,并且是成功的。但是,在使用正确的目录打开操作系统窗口后,我的tkinker GUI挂起并且无用。这是我第一次使用多线程,谢谢你。

"""
Script lunches GUI with text field and search button
Text field arg = WR # string
Search button event = calls Search
Search func looks in F:/WEST/* and F:/NORTH/* directories for WR # directory
Search func gets WR # directory
Search func opens WR # directory window in OS
"""

#Libaries
from tkinter import *
import glob
import os
import threading
import time
from queue import *


def search():
    """
    Searchs through NORTH and WEST directories
    Finds folder paths recursively with WR number at end of path name
    Calls os.startfile to Open the folder
    :return:NULL
    """
    wrNumber = e1.get()
    northPath   = 'F:/NORTH/**/**/**/**/*'
    westPath    = 'F:/WEST/**/**/**/**/*'

    for folderName in glob.iglob(westPath + str(wrNumber), recursive=True) \
                or glob.iglob(northPath + str(wrNumber), recursive=True):
        print(folderName)
        print(str(wrNumber))

        os.startfile(str(folderName))


#Initializes basic GUI window elements
master = Tk()

#Create GUI Title = 'WR# Searcher'
master.title("WR# Searcher")

#Create Label e1 = 'WR#'
Label(master, text="WR #", ).grid(row=0)
e1 = Entry(master)
e1.grid(row=0, column=1)

#Create Button Button = 'Search'
Button(master, text='Search', command=search).grid(row=0, column=2, sticky=W, pady=4)

master.mainloop()

0 个答案:

没有答案