[英]TypeError: write() argument must be str, not Entry
does anyone have any idea on how can i write the inserted text to a label in a.txt file?有人知道如何将插入的文本写入 a.txt 文件中的 label 吗?
my code:我的代码:
from tkinter import *
root = Tk()
root.title('مستلزمات البيت')
label1 = Entry(root, width=30)
label1.grid(row=1, column=0, columnspan=3)
e = ["-", label1]
lable2 = Label(root, text="اسم الغرض ")
lable2.grid(row=0, column=2)
f = open("house.txt", "a")
def clear():
f.write(e[1])
label1.delete(0, END)
f.close()
enter_btn = Button(root, width=80, padx=50, pady=50, text="تأكيد", command=clear)
enter_btn.grid(row=2, column=0, columnspan=3)
root.mainloop()
when i run it this appears:当我运行它时,会出现:
File "C:\Users\yahya.ashwaq-PC\PycharmProjects\jad el jad\mostalzamat.py", line 21, in clear
f.write(e[1])
TypeError: write() argument must be str, not Entry
The probem here is that your file is called "tkinter.py", when you use from tkinter import *
You just import you file... Just rename your file!这里的问题是您的文件名为“tkinter.py”,当您使用from tkinter import *
您只需导入您的文件...只需重命名您的文件!
Next time you ask for help, copy and paste the code, DO NOT upload image of your code下次您寻求帮助时,请复制并粘贴代码,请勿上传代码图片
Try writing this试着写这个
import tkinter
root = tkinter.Tk()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.