使用Tkinter导入后端应用程序 - Python

时间:2017-10-09 20:13:11

标签: python user-interface tkinter

我编写了一个tkinter应用程序,它将文件发送到导入的后端应用程序,以便在单击“转换”按钮时进行处理。在运行GUI时,我看到后端应用程序运行但是当我单击按钮时出现此错误:IOError:[Errno 13]权限被拒绝:'C:/ Users / import'

我认为这是因为在导入时,后端应用程序在后台运行,因此当单击该按钮时,我无法打开已打开的应用程序。这是真的?有没有办法设置GUI,所以后端应用程序只在我点击按钮时运行?

import os
from Tkinter import *
from tkFileDialog import askopenfilename
import EE_Import

content = ''
file_path = ''

def subMenu():
    pass

def get_previous_provider(event):
    print('Paychex')

def get_platform_list(event):
    return('Flex')

def import_list(event):
    print('Employee Import')

def open_file():
    global content
    global file_path

    filename = askopenfilename()
    infile = open(filename, 'r')
    content = infile.read()
    file_path = os.path.dirname(filename)
    locEntry.delete(0, END)
    locEntry.insert(0, file_path)
    return content

def convert():
    x = locEntry.get()  #sends file name to EE_Import to process
    EE_Import_Paychex_Flex.open_sesame(x)





root = Tk()
root.wm_title("Import")

# ---- Menu Line
menuLine = Menu(root)
root.config(menu=menuLine)

# ---- File Submenu
fileMenu = Menu(menuLine)
menuLine.add_cascade(label="File", menu=fileMenu)
fileMenu.add_command(label="Help", command=subMenu)
fileMenu.add_separator()
fileMenu.add_command(label="Exit", command=root.destroy)

# ---- Browse Button to select where your file is
browseButton = Button(root, text="Browse", command=open_file)
browseButton.grid(row=0, column=0, padx=2, pady=2)

file_path = StringVar()
locEntry = Entry(root, textvariable=file_path, width=40)
locEntry.grid(row=0, column=1, padx=2, pady=2)

# ---- List that allows the user to select their options out of what is available
provList = Listbox(root, width=50)
provList.grid(row=2, column=0, padx=2, pady=2, columnspan=3)
provList.bind('<<ListboxSelect>>', get_previous_provider)

# ---- Button that will start the conversion process
goButton = Button(root, text="Convert", command=convert)
goButton.grid(row=3, column=0, padx=2, pady=2)

root.mainloop()

0 个答案:

没有答案