3 回答

TA貢獻1835條經驗 獲得超7個贊
'NoneType' 對象不可調用錯誤是由將對象放置在定義的位置引起的。所以而不是
Label_1 = Label(master,text="The file selected: "+file_path).grid(row=1,column=0)
嘗試:
Label(master,text="The file selected: "+file_path).grid(row=1,column=0)
或者
Label_1 = Label(master,text="The file selected: "+file_path) Label_1.grid(row=1,column=0)
也不要使用 Button = Button(master... 而是給變量一個唯一的名稱

TA貢獻1784條經驗 獲得超8個贊
這是答案:
from tkinter import *
from tkinter import filedialog
import tkinter as tk
import pandas as pd
import pyodbc
from sqlalchemy import create_engine
import urllib
master = Tk()
master.title("Demo GUI")
master.geometry("900x400+150+150")
master.resizable(0,0)
def browse_file():
global file_path
global data_frame
file_path = filedialog.askopenfilename(title = "Choose the file to upload")
data_frame = pd.read_excel(file_path)
Label = Label(master,text="Choose the file to upload").grid(row=0)
Button = Button(master,text='Browse',command = browse_file).grid(row=0,column=1,pady=4)
Label_1 = tk.Label(master,text="The file selected: "+file_path).grid(row=1,column=0)
master.mainloop()

TA貢獻1828條經驗 獲得超6個贊
您所做的錯誤是一個錯字:通過編寫:
Label = Label(master,text="Choose the file to upload").grid(row=0)
您將grid
調用結果分配給原始 tk.Label 類型 ( Label
)。網格回電是None
因此,當您嘗試創建 Label1 時,您實際上是在調用現在的 LabelNone
只需將行替換為:
l = Label(master,text="Choose the file to upload") l.grid(row=0)
或者干脆
Label(master,text="Choose the file to upload").grid(row=0)
添加回答
舉報