I'm a complete beginner at Python and am trying to make an interactive project with what I'm writing.
To start off, here's an example of what I'm doing.
from tkinter import *
window = Tk()
window.title("I am a title")
window.minsize(width=700, height=300)
canvas = Canvas(width=900, height=400)
canvas.grid(column=3,row=3)
def button_1_pressed():
print("You pressed button 1!")
def button_2_pressed():
print("You pressed button 2!")
def start():
label = Label(text="I am a label! \nWill you press a button?")
label.grid(column=2, row=0)
button_1 = Button(window, text="Button 1", command=button_1_pressed)
button_1.grid(column=2, row=1)
button_2 = Button(window, text="Button 2", command=button_2_pressed)
button_2.grid(column=2, row=2)
start()
window.mainloop()
What I want to happen is for the label text to change after pressing a button and for the buttons to disappear and then be replaced with a text entry box. The problem is that I've looked into this and have come across the destroy command but for some reason, it doesn't appear to work in this instance. All I get is a NameError. Is it because the buttons I'm telling it to destroy are only defined within a function?
from tkinter import *
window = Tk()
window.title("I am a title")
window.minsize(width=700, height=300)
canvas = Canvas(width=900, height=400)
canvas.grid(column=3,row=3)
def start():
label = Label(text="I am a label! \nWill you press a button?")
label.grid(column=2, row=0)
button_1 = Button(window, text="Button 1", command=button_1_pressed)
button_1.grid(column=2, row=1)
button_2 = Button(window, text="Button 2", command=button_2_pressed)
button_2.grid(column=2, row=2)
def button_1_pressed():
print("You pressed button 1!")
button_1.destroy()
def button_2_pressed():
print("You pressed button 2!")
button_2.destroy()
start()
window.mainloop()