[問題] 區域,全域變數問題求解
各位版友好,最近遇到了一個問題,不知是否能撥空幫忙看要如何修改
問題是用tkinter的filedialog選取檔案,然後將所選取的路徑丟給excel處理
看起來問題是函式內的區域變數無法拿到全域使用,但google了好一陣子仍不知如何修改
麻煩各位幫個忙
感激不盡!
Fail訊息如下
NameError: name 'report_fileselect' is not defined
code如下:
import tkinter
from openpyxl import load_workbook
from tkinter import filedialog
root = tkinter.Tk()
Text_0 = tkinter.Label(root, text="Select")
Text_0.grid(row=0, column=0)
def report_select():
combine_fileselect =
filedialog.askopenfilenames(title="Choose file",multiple=True,filetypes=[("xlsm files","*.xlsm")])
BTN_0 =tkinter.Button(root,width=12,text="",command=report_select,borderwidth=4)
BTN_0.grid(row=0, column=1,sticky="WE")
def QPD_select():
global report_fileselect
report_fileselect=
filedialog.askopenfilename(initialdir="c:",title="Choose
QPD",filetypes=[("xlsm files","*.xlsm")])
BTN_1 =
tkinter.Button(root,width=12,text="",command=QPD_select,borderwidth=4)
BTN_1.grid(row=1, column=1,sticky="WE")
wb = load_workbook(report_fileselect, keep_vba=True, read_only=False)
sheet = wb.get_sheet_by_name("Result")
root.mainloop()
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.88.57
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1488801457.A.E3D.html
→
03/06 20:19, , 1F
03/06 20:19, 1F
→
03/06 20:59, , 2F
03/06 20:59, 2F
→
03/06 21:00, , 3F
03/06 21:00, 3F
→
03/06 21:01, , 4F
03/06 21:01, 4F
→
03/07 12:40, , 5F
03/07 12:40, 5F
→
03/07 12:41, , 6F
03/07 12:41, 6F
Python 近期熱門文章
PTT數位生活區 即時熱門文章