如你所见,我是新来的。我已经研究过答案,但找不到适合我的答案。
我想用浏览器选择一个 excel 文件(由 tktinker 创建)并将其用于我的 pandas 工作。我的代码是:
from tkinter import *
import os
import tkinter as tk
import shutil
from tkinter import messagebox as mb #import the mesassage box for displaying the messages
from tkinter import filedialog as fd
import tkinter.ttk as ttk
# Create the root window
window = tk.Tk()
def browseFiles():
file1 = fd.askopenfilename(parent=window, initialdir = "/",
title = "Welches File wünschst Du",
filetypes = (("Text files",
"*.txt*"),
("Excel files",
"*.xlsx*"),
("all files",
"*.*")))
label_file_explorer.configure(text="File Opened: "+file1) # Change label contents
print(file1)
return str(file1)
# Function for opening the
# file explorer window
style = ttk.Style(window)
style.theme_use("clam")
# Set window title
window.title('File Explorer')
# Set window size
window.geometry("500x300")
# Set window background color
window.config(background = "pink")
# Create a File Explorer label
label_file_explorer = Label(window,
text = "File Explorer for etamax.",
width = 100, height = 4,
fg = "blue")
button_explore = Button(window,
text = "Browse Files",
command = browseFiles)
button_exit = Button(window,
text = "Ausfahrt",
command = exit)
# Grid method is chosen for placing
# the widgets at respective positions
# in a table like structure by
# specifying rows and columns
label_file_explorer.grid(column = 1, row = 1)
button_explore.grid(column = 1, row = 2)
button_exit.grid(column = 1,row = 3)
# Let the window wait for any events
window.mainloop()
但是当我想将此文件与 pandas 一起使用时,我没有任何响应(没有错误消息或没有响应)它只是等待。 (我的 python 版本是:3.8.8)
df2=pd.read_excel(file1)
df=df2.copy()`
提前非常感谢您的所有好心回答
我希望使用浏览器来选择文件以使用 pandas 对其进行操作