Top Level Widget (Mini Project)
from tkinter import *
root = Tk()
root.title("Root Or Main Window")
root.geometry("600x245+700+86")
root.config(bg="#C6E2FF")
label1 = Label(root, text="I AM ROOT WINDOW",bg="#C6E2FF", font=("Times New Roman", 20, "bold"))
label1.pack(pady=20)
def terminate():
lbl = Label(root, text="Work Done")
lbl.pack()
def click_Toplevel2():
toplevel2 = Toplevel(root)
toplevel2.title("TOP LEVEL 2")
toplevel2.geometry("430x245+500+360")
toplevel2.config(bg="#8E8E38")
lbl = Label(toplevel2, text="I AM TOP LEVEL 2 WINDOW",bg="#8E8E38",font=("Times New Roman", 20, "bold"))
btn1 = Button(toplevel2, text="Yes, I AM TOP LEVEL 2",font=("Times New Roman", 20, "bold"),bg="#71C671", command=terminate)
btn2 = Button(toplevel2, text="Exit",font=("Times New Roman", 20, "bold"),bg="#7A67EE",command=toplevel2.destroy)
lbl.pack(pady=20)
btn1.pack(pady=10)
btn2.pack(pady=30)
toplevel2.mainloop()
def click_Toplevel1():
toplevel1 = Toplevel(root)
toplevel1.title("TOP LEVEL 1")
toplevel1.geometry("410x245+300+86")
toplevel1.config(bg="#EE8262")
lbl = Label(toplevel1, text="I AM TOP LEVEL 1 WINDOW",bg="#EE8262",font=("Times New Roman", 20, "bold"))
btn1 = Button(toplevel1, text="OPEN TOP LEVEL 2",font=("Times New Roman", 20, "bold"),command=click_Toplevel2,bg="#FFFF00")
btn2 = Button(toplevel1, text="Exit",font=("Times New Roman", 20, "bold"),bg="#7A67EE",command=toplevel1.destroy)
lbl.pack(pady=20)
btn1.pack(pady=10)
btn2.pack(pady=30)
toplevel1.mainloop()
btn = Button(root, text="Click Top level 1", font=("Times", 20,"bold"),bg="#EE799F",command=click_Toplevel1)
btn.pack(pady=40)
root.mainloop()
Write Down Code Your Code Editor. To show Your Output. If Use Pycharm Press Shift+F10 and Show Your Output.
It You Like this Plz Share
ردحذفfrom tkinter import *
ردحذفroot = Tk()
root.title("Root Or Main Window")
root.geometry("600x245+700+86")
root.config(bg="#C6E2FF")
label1 = Label(root, text="I AM ROOT WINDOW",bg="#C6E2FF", font=("Times New Roman", 20, "bold"))
label1.pack(pady=20)
def terminate():
lbl = Label(root, text="Work Done")
lbl.pack()
def click_Toplevel2():
toplevel2 = Toplevel(root)
toplevel2.title("TOP LEVEL 2")
toplevel2.geometry("430x245+500+360")
toplevel2.config(bg="#8E8E38")
lbl = Label(toplevel2, text="I AM TOP LEVEL 2 WINDOW",bg="#8E8E38",font=("Times New Roman", 20, "bold"))
btn1 = Button(toplevel2, text="Yes, I AM TOP LEVEL 2",font=("Times New Roman", 20, "bold"),bg="#71C671", command=terminate)
btn2 = Button(toplevel2, text="Exit",font=("Times New Roman", 20, "bold"),bg="#7A67EE",command=toplevel2.destroy)
lbl.pack(pady=20)
btn1.pack(pady=10)
btn2.pack(pady=30)
# Display until closed manually
toplevel2.mainloop()
def click_Toplevel1():
toplevel1 = Toplevel(root)
toplevel1.title("TOP LEVEL 1")
toplevel1.geometry("410x245+300+86")
toplevel1.config(bg="#EE8262")
lbl = Label(toplevel1, text="I AM TOP LEVEL 1 WINDOW",bg="#EE8262",font=("Times New Roman", 20, "bold"))
btn1 = Button(toplevel1, text="OPEN TOP LEVEL 2",font=("Times New Roman", 20, "bold"),command=click_Toplevel2,bg="#FFFF00")
btn2 = Button(toplevel1, text="Exit",font=("Times New Roman", 20, "bold"),bg="#7A67EE",command=toplevel1.destroy)
lbl.pack(pady=20)
btn1.pack(pady=10)
btn2.pack(pady=30)
# Display until closed manually
toplevel1.mainloop()
# Create button to open toplevel1
btn = Button(root, text="Click Top level 1", font=("Times", 20,"bold"),bg="#EE799F",command=click_Toplevel1)
btn.pack(pady=40)
# Display until closed manually
root.mainloop()
إرسال تعليق