I have some questions about the following code:
from tkinter import *
def create_window():
new_window = Tk()
old_window.destroy()
Label(new_window,text='hi').pack()
old_window = Tk()
Button(old_window,text="create new window!",command=create_window).pack()
old_window.mainloop()
Why is label used here instead of just writing text= in new_window? And how does label actually work?
I searched for this topic on YouTube, but I did not find an answer to my question. They just write a label without any explanation as to why.
Label is a widget that implements a display box where you can place text or images. The text displayed by this widget can be updated at any time you want.
So this line:
Label(new_window,text='hi').pack()
Does the following: create a text saying hi in the window called new_window, then displays it by using the .pack() method