I am a beginner programmer and I am trying to solve a very small problem. I want to make a GUI which has 2 buttons namely, Print and Clear. I tried my best but cant solve it yet. Wanted Help.... Here is my code( ignore neatness ):
from tkinter import *
main = Tk()
main.geometry("200x200")
global buttonstate
def change():
buttonstate = True
return buttonstate
button1 = Button(main, text="Button", command=change)
if buttonstate==True:
global label
label = Label(main, text= "this works")
elif buttonstate==False:
pass
button2 = Button(main, text="clear", command=lambda: label.pack_forget())
button1.pack()
button2.pack()
label.pack()
main.mainloop()
I am unable to do all the thing in a loop and also to print the statement when the button is clicked... Thanks.