python - 将数据从 Kivy Python 更新到 Excel
问题描述
我在更新要插入到 excel 的数据时遇到问题。起初,我创建了数据,它成功地工作而没有错误。在我想从 Kivy 插入新数据后,它不起作用。错误表示该过程被 PC 拒绝。我有观看教程,看来我的问题仍未解决。这是我来自 VSCode 的代码:
Window.size = (500, 500)
outWorkbook = xlsxwriter.Workbook("staff.xlsx") outSheet = outWorkbook.add_worksheet()
类菜单(屏幕):通过
类输入(屏幕):
input1 = ObjectProperty(None)
input2 = ObjectProperty(None)
input3 = ObjectProperty(None)
input4 = ObjectProperty(None)
input5 = ObjectProperty(None)
input6 = ObjectProperty(None)
def clear(self):
self.ids.inherent_input.text = ''
self.ids.inherent2_input.text = ''
self.ids.inherent3_input.text = ''
self.ids.inherent4_input.text = ''
self.ids.inherent5_input.text = ''
self.ids.inherent6_input.text = ''
def btn(self):
self.L = ()
print("Name: " + self.input1.text,
"Activity/Programme: " + self.input2.text,
"Date: " + self.input3.text,
"Place: " + self.input4.text,
"Time from: " + self.input5.text,
"Time to: " + self.input6.text)
staff = ({"Name": [str(self.input1.text)], "Program/Activity": [str(self.input2.text)], "Place" : [str(self.input3.text)], "Date": [str(self.input4.text)], "Time From" : [str(self.input5.text)], "Time To" : [str(self.input6.text)]})
self.L = pd.DataFrame(staff)
self.input1.text = ''
self.input2.text = ''
self.input3.text = ''
self.input4.text = ''
self.input5.text = ''
self.input6.text = ''
print(self.L)
with pd.ExcelWriter('staff.xlsx') as writer:
self.L.to_excel(writer)
类信息(屏幕):通过
类 WindowManager(ScreenManager):通过
kv = Builder.load_file('window.kv')
类我的布局(小部件):
类 WindowApp(App): def build(self): return kv
如果名称== '主':WindowApp().run()
这是我的 kv 文件:
WindowManager:
Menu:
Enter:
Info:
:名称:“主菜单”
BoxLayout:
orientation: "vertical"
size: root.width, root.height
padding: 10
spacing: 15
Button:
id: enter
text: "Enter"
on_release: app.root.current = "enter"
Button:
id: info
text: "Information"
on_release: app.root.current = "info"
Button:
id: exit
text: "Exit"
on_press: quit()
:名称:“输入”
input1: inherent_input
input2: inherent2_input
input3: inherent3_input
input4: inherent4_input
input5: inherent5_input
input6: inherent6_input
BoxLayout:
orientation: "vertical"
size: root.width, root.height
padding:10
spacing:10
BoxLayout:
spacing: 10
Label:
text: "Name"
font_size: 20
TextInput:
id: inherent_input
multiline: False
BoxLayout:
spacing: 10
Label:
text: "Activity/Programme"
font_size: 20
TextInput:
id: inherent2_input
multiline: False
BoxLayout:
spacing: 10
Label:
text: "Place"
font_size: 20
TextInput:
id: inherent3_input
multiline: False
BoxLayout:
Label:
text: "Date"
font_size: 20
TextInput:
id: inherent4_input
multiline: False
BoxLayout:
padding: 10
spacing: 10
Label:
text: "Time from"
font_size: 20
TextInput:
id: inherent5_input
multiline: False
Label:
text: "to"
font_size: 20
TextInput:
id: inherent6_input
multiline: False
BoxLayout:
padding: 15
spacing: 15
Button:
id: clear
text: "Clear"
font_size: 12
on_press: root.clear()
Button:
id: back
text: "Back to Menu"
font_size: 12
on_release: app.root.current = "MainMenu"
Button:
id: submit
text: "Submit"
font_size: 12
on_press: root.btn()
:名称:“信息”
BoxLayout:
orientation: 'vertical'
padding: 15
spacing: 15
Label:
id: information
text: "This is just a test, an Alpha version of Prototype"
font_size: 20
bold: True
italic: False
outline_color: (0,0,0)
Button:
id: returnBack
text: "Return"
on_release: app.root.current = "MainMenu"
任何帮助将不胜感激。
解决方案
您遇到的错误可能意味着多种情况。
你想打开一个目录吗?
如果是这样,请不要这样做。它很可能会导致您提到的错误。
您尝试打开的文件是否在其他任何地方?
您可能必须关闭它,python 才能打开它。在尝试删除资源管理器中的文件时,您可能已经经历过这种情况,该文件在其他地方打开。Windows 不会让你这样做。在尝试访问之前检查有问题的文件是否已打开。
推荐阅读
- r - 如何在 R 中制作带有可格式化的表格?
- java - Spring -MVC 在控制器中使用会话属性
- python - 我正在尝试添加时间。我得到 <__main__.MyTime object at 0x039C55C8>。但我期待我的两次添加
- mysql - 复杂数据库模型 MySql 所需的建议
- docker - 远程开发容器——迁移到 Docker Compose
- javascript - eslint-laoder 构建失败,即使 failOnError 设置为 false
- jquery - jQuery - 在 keyup 上从数组更改 CSS
- qt - 如何使用 Qt Creator 进行编译
- flutter - 如何使中间容器与其他两个不同?
- java - 使用 axios 从 react js 调用 spring boot get 方法时,浏览器显示“请求已被 CORS 策略阻止”