Привет! Я пытаюсь использовать tkinter для создания страницы с кнопкой, которая при нажатии изменит состояние поля ввода на этой странице с обычного только на чтение.
Вот мой код, гдефункция, вызываемая кнопкой, находится внутри класса, мой скрипт все еще выполняется, но кнопка ничего не делает:
class playlist(tkinter.Frame): #creates playlist page
def __init__(self, parent, controller):
tkinter.Frame.__init__(self, parent)
A4 = tkinter.Canvas(self, bg="black", bd=20, height=1080, width=1920, relief="sunken") #creates black background
AC = tkinter.Label(self, bg="white", bd=5, height=45, width=225,) #creates white canvas
B1 = tkinter.Button(self, anchor="center", height=1, width=6, bg="#16EBF2", activebackground="#23F216", relief="sunken",
font=("Elephant", 24), text="Home", command=lambda: controller.show_frame(homepage))
B2 = tkinter.Button(self, anchor="center", height=1, width=4, bg="#16EBF2", activebackground="#23F216", relief="sunken",
font=("Elephant", 24), text="Edit", command=lambda: edit)
E1 = tkinter.Entry(self, state="readonly", text="Name:", bd=5, bg="red", font=("Elephant", 24), exportselection=0)
E1.pack()
A4.pack(fill="both", expand=True)
AC.pack()
B1.pack()
B2.pack()
A4.create_window(960, 550, anchor="center", window=AC) #puts new canvas on background
A4.create_window(200, 80, anchor="center", window=B1) #adds buttons to canvas
A4.create_window(960, 80, anchor="center", window=E1)
A4.create_window(650, 80, anchor="center", window=B2)
def edit():
E1.configure(state = "normal")
B2.configure(text="Done")
E1.pack()
B2.pack()
App.update_idletasks()
таким образом, функция не может определить E1 или B2, поэтому я попробовал версию, в которой функция находится в первой функции:
class playlist(tkinter.Frame): #creates playlist page
def __init__(self, parent, controller):
tkinter.Frame.__init__(self, parent)
A4 = tkinter.Canvas(self, bg="black", bd=20, height=1080, width=1920, relief="sunken") #creates black background
AC = tkinter.Label(self, bg="white", bd=5, height=45, width=225,) #creates white canvas
B1 = tkinter.Button(self, anchor="center", height=1, width=6, bg="#16EBF2", activebackground="#23F216", relief="sunken",
font=("Elephant", 24), text="Home", command=lambda: controller.show_frame(homepage))
B2 = tkinter.Button(self, anchor="center", height=1, width=4, bg="#16EBF2", activebackground="#23F216", relief="sunken",
font=("Elephant", 24), text="Edit", command=lambda: edit)
E1 = tkinter.Entry(self, state="readonly", text="Name:", bd=5, bg="red", font=("Elephant", 24), exportselection=0)
E1.pack()
A4.pack(fill="both", expand=True)
AC.pack()
B1.pack()
B2.pack()
A4.create_window(960, 550, anchor="center", window=AC) #puts new canvas on background
A4.create_window(200, 80, anchor="center", window=B1) #adds buttons to canvas
A4.create_window(960, 80, anchor="center", window=E1)
A4.create_window(650, 80, anchor="center", window=B2)
def edit():
E1.configure(state = "normal")
B2.configure(text="Done")
E1.pack()
B2.pack()
App.update_idletasks()
таким образом, сценарий все еще выполняется, а кнопка по-прежнему ничего не делает.Без ошибок просто не работает.Заранее спасибо:)