-5

does anyone have any idea on how can i write the inserted text to a label in a .txt file?

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
yahyayt5
  • 1
  • 2
  • 1
    Please paste the code and error instead of using images to show it. – Girish Jan 26 '21 at 14:19
  • 1
    Please include relevant excerpts from the code and the output in the post itself rather than linking to images elsewhere. – Kemp Jan 26 '21 at 14:20
  • 2
    `C:\Users\yahya.ashwaq-PC\Desktop\yahya\tkinter.py` is this file is created by you? If yes rename it to other name and try to run your code. – Girish Jan 26 '21 at 14:31
  • See https://stackoverflow.com/q/36250353/3890632 – khelwood Jan 26 '21 at 14:32
  • It is better to raise another question instead of changing the question completely. All the comments and answers given before seemed not relevant now. – acw1668 Jan 27 '21 at 08:51

2 Answers2

1

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!

Next time you ask for help, copy and paste the code, DO NOT upload image of your code

Fredericka
  • 296
  • 1
  • 7
-1

Try writing this

import tkinter
root = tkinter.Tk()
Dharman
  • 30,962
  • 25
  • 85
  • 135
Mini N
  • 51
  • 1
  • 1
  • 1