I always thought that only frame and other container elements can be parent, but recently when I tried the below code, it seemed to work perfectly without any error.
import os
import tkinter as tk
from PIL import Image, ImageTk
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
main = tk.Tk()
main.title("Main Window")
main.config(bg="#E4E2E2")
main.geometry("700x400")
frame = tk.Frame(master=main)
frame.config(bg="#d1c9c9")
frame.pack()
label2 = tk.Label(master=frame, text="Password")
label2.config(bg="#d1c9c9", fg="#000")
label2.pack(side=tk.TOP)
button = tk.Button(master=frame, text="Submit")
button.config(bg="#161515", fg="#ffffff")
button.pack(side=tk.TOP)
entry1 = tk.Entry(master=button)
entry1.config(bg="#fff", fg="#000")
entry1.pack(side=tk.TOP)
main.mainloop()
The entry seems to be appearing inside the button when i try it on my linux PC. So, is it fine to use labels, button widgets and others as parents? Will it cause any issues on other OS?
Any widget can be the parent of another widget. While unusual, it's perfectly acceptable to make a label or a button a parent of another widget. This might not always work the way you expect though, since some widgets have interactive behaviors that won't account for child widgets.
For example, if you add another button as a child of a button, either the parent or child button may not work the way you expect when you click on it.
I advise not using buttons as a parent. There are usually better ways to solve whatever problem you are trying to solve.