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)
添加回答
举报