3 回答

TA貢獻(xiàn)1835條經(jīng)驗(yàn) 獲得超7個(gè)贊
'NoneType' 對(duì)象不可調(diào)用錯(cuò)誤是由將對(duì)象放置在定義的位置引起的。所以而不是
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... 而是給變量一個(gè)唯一的名稱

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超8個(gè)贊
這是答案:
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貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超6個(gè)贊
您所做的錯(cuò)誤是一個(gè)錯(cuò)字:通過(guò)編寫:
Label = Label(master,text="Choose the file to upload").grid(row=0)
您將grid
調(diào)用結(jié)果分配給原始 tk.Label 類型 ( Label
)。網(wǎng)格回電是None
因此,當(dāng)您嘗試創(chuàng)建 Label1 時(shí),您實(shí)際上是在調(diào)用現(xiàn)在的 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)
添加回答
舉報(bào)