S
S
sandul232021-11-20 22:03:45
Python
sandul23, 2021-11-20 22:03:45

How to fix insert problem in python(TKINTER)?

I KNOW THE CODE IS HORRIBLE AND IS GENERALLY WRITTEN ON YOUR KNEES.
I WRITE AS WELL AS I CAN.

God knows, I did not want to turn to anyone for help, but I will have to, because there is no mention of this problem anywhere.
What is the point?
I'm doing something like a PL, I've tried it many times and it doesn't work. But then I decide to make an IDE.
In other words, I started with him.
The task of my under-program is to simply open a JS file. First, we should have a window where we are asked to enter the path to the file, and then we have an editing window where the contents of the file should be displayed.
But what is it? That's right. Not highlighted and generously sprinkles the console with errors.

Errors when clicking on the button to go to the editor window:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39-32\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args )
File "C:\Users\Admin\Desktop\EFScript\EFScript IDE.py", line 38, in OPENFUNCFile
EFOPENFile = i_nameOF.get("1.0", "end-1c")
File "C:\Users\Admin\ AppData\Local\Programs\Python\Python39-32\lib\tkinter\__init__.py", line 3711, in get
return self.tk.call(self._w, 'get', index1, index2)
_tkinter.TclError: invalid command name ".!text"

Code:

from tkinter import *
#Начало.Открытие окна,в котором вводится расположение файла.После,содержимое файла записывается и вставляется в форму.
OpenFile = Tk()
OpenFile.title("Среда разработки EFScript|Открыть файл")
OpenFile.geometry('800x400')
nameOF = Label(text="Введите путь к файлу",font=("Arial Bold", 35))
i_nameOF = Text(width=100,height=5)
nameOF.pack()
i_nameOF.pack()
def compil():
    EFcode = text_box.get("1.0", "end-1c")
    EFFile = i_name.get("1.0", "end-1c")
    EFName = EFFile+ '.'+"js"
    print(EFcode)
    print(EFName)
def OPENFUNCFile():
    window = Tk()
    window.title("Среда разработки EFScript")
    window.geometry('800x400')
    zglone = Label(window,text="Введите код",font=("Arial Bold", 35))
    text_box = Text(window,width=100,height=10)
    name = Label(window,text="Введите название файла",font=("Arial Bold", 35))
    i_name = Text(window,width=100,height=5)
    button = Button(
        window,
        text="Обработать",
        width=25,
        height=3,
        bg="blue",
        fg="yellow",
    )
    command=compil,
    global EFOPENFile
    global OFNF
    global OFRF
    OpenFile.destroy()
    EFOPENFile = i_nameOF.get("1.0", "end-1c")
    OFNF = open(EFOPENFile, 'r+', encoding="UTF-8")
    OFRF = OFNF.read()
    name.pack()
    i_name.pack()
    zglone.pack()
    text_box.pack()
    button.pack()
    OpenFile.destroy()
    text_box.delete(0,"end")
    text_box.insert(0, OFRF)
    i_name.delete(0,"end")
    i_name.insert(0, OFRF)
    print(EFOPENFile)
    print(OFRF)
    window.mainloop()

buttonOF = Button(
    text="Открыть файл",
    width=25,
    height=3,
    bg="blue",
    fg="yellow",
    command=OPENFUNCFile
)
buttonOF.pack()
OpenFile.mainloop()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-11-20
@sandul23

You close the window first, then you try to get the data that was in that window.
Throw somewhere higher , up to . Well, you have two destroy EFOPENFile = i_nameOF.get("1.0", "end-1c")OpenFile.destroy()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question