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

2024-09-30 20:32:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我写了一个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()

Tags: topathimport应用程序getdefrootopen