我的python程序没有保存在excel文件中



我的python程序只保存第一行,不保存其他列。在我的Track.xlsx文件中,当我按下保存按钮时,程序只保存第一行,其余的不保存,就好像它没有考虑到各种文本框和组合框中的文本一样。

我是个初学者,有人能帮我吗?

from cProfile import label
from copyreg import clear_extension_cache
from distutils.command.clean import clean
from importlib.resources import path
from sqlite3 import Row
from tkinter import filedialog
import pandas
from openpyxl import *
from tkinter.messagebox import showinfo
from ast import main
from cgitb import text
#import curses
#from curses.textpad import tb
#import email
from faulthandler import disable
from multiprocessing.sharedctypes import Value
from operator import index
from tkinter import *
import tkinter as tk
from tkinter.messagebox import showinfo
from tkinter.ttk import Combobox
from turtle import pd, width
from unicodedata import name
from webbrowser import get
import openpyxl
import xlrd
from openpyxl import workbook
import pathlib
# Comandi
def load():
path=filedialog.askopenfilename()
df=pandas.read_excel(path)
print(df)
def save():
mese = entry2.get()
altezza = entry3.get()
peso = entry4.get()
mmagra = entry5.get()
mgrassa = entry6.get()
utente = entry7.get()
wb = Workbook()
ws = wb.active
ws['A1'] = "Mese"
ws['B1'] = "Altezza"
ws['C1'] = "Peso"
ws['D1'] = "Massa Magra"
ws['E1'] = "Massa Grassa"
ws['F1'] = "Utente"
ws['A2'] = mese
ws['B2'] = altezza
ws['C2'] = peso
ws['D2'] = mmagra
ws['E2'] = mgrassa
ws['F2'] = utente
wb.save(r'C:UserslricciDesktopSERVERwebGym TrackerGym Tracker v1.0track.xlsx')
showinfo("Salvataggio")
file1 = pandas.read_excel("track.xlsx")
file2 = pandas.read_excel("trackn.xlsx")
all = [file1, file2]
append = pandas.concat(all)
append.to_excel("track.xlsx", index=False)
def delete():
entry2.delete(0, tk.END)
entry3.delete(0, tk.END)
entry4.delete(0, tk.END)
entry5.delete(0, tk.END)
entry6.delete(0, tk.END)
entry7.delete(0, tk.END)
# Main frame
windows = tk.Tk()
windows.geometry("400x350")
windows.title("Gym Tracker")
windows.resizable(False, False)
#Frame 2
frame1 = Frame(windows, width=150, height=30, highlightcolor="white",highlightbackground="black", highlightthickness=1).place(x=120, y=2)
label1= Label(windows, text="GYM TRACKER").place(x=150, y=7)
frame2 = Frame(windows, width=500, height=1, highlightcolor="white",highlightbackground="black", highlightthickness=1).place(x=2, y=45)
# Combobox Mese
label2 = Label(windows, text="Mese").place(x=110, y=60)
cb1 = Combobox(windows, values=['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno','Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre']).place(x=200, y=60)
entry2 = tk.Entry(windows)
label3 = Label(windows, text="Altezza").place(x=110, y=90)
tb3 = Text(windows, width=17, height=1).place(x=200, y=90)
entry3 = tk.Entry(windows)
label4 = Label(windows, text="Peso").place(x=110, y=120)
tb4 = Text(windows, width=17, height=1).place(x=200, y=120)
entry4 = tk.Entry(windows)
label5 = Label(windows, text="Massa Magra").place(x=110, y=150)
tb5 = Text(windows, width=17, height=1).place(x=200, y=150)
entry5 = tk.Entry(windows)
label6 = Label(windows, text="Massa Grassa").place(x=110, y=180)
tb6 = Text(windows, width=17, height=1).place(x=200, y=180)
entry6 = tk.Entry(windows)
# Combobox Utente
label7 = Label(windows, text="Utente").place(x=110, y=210)
combobox = Combobox(windows, values=['Erika', 'Lorenzo']).place(x=200, y=210)
entry7 = tk.Entry(windows)
# Bottoni
btdelete = tk.Button(windows, text="Elimina", command=delete ,width=8, height=1).place(x=170, y=310)
btload = tk.Button(windows, text="Load", width=8, height=1,command=load).place(x=300, y=310)
btsave = tk.Button(windows, text="Salva", width=8, height=1, command=save).place(x=50, y=310)
windows.mainloop()

两个导入名称冲突:

import pandas as pd

from turtle import pd, width

因此,当您使用pd调用pandas函数时,Python会尝试在turtlepd函数上调用它们。

(您可以注意到这个错误是关于一个函数的,因为pd是海龟包的一个函数,而不是像pandas那样的模块(。

要解决此问题,当您需要turtle中的pd函数时,应导入海龟包import turtle并使用turtle.pd(),当您使用pandas模块时,应直接使用pd

最新更新