Hey I'm just wondering how to make pop-up windows in tkinter.

Recommended Answers

All 2 Replies

Typical example:

''' tk_toplevel_window101.py
create a toplevel popup window that overlaps the root window
'''

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def popup_window():
    window2 = tk.Toplevel(root)
    # give window2 a position to overlap the root window
    window2.geometry("200x200+{}+{}".format(150, 150))
    window2.title("window2")
    window2['bg'] = 'yellow'
    tk.Button(window2, text='Leave window2', command=window2.destroy).pack()

root = tk.Tk()   # root is a toplevel window
# set 200x200 window upper left corner to x=100, y=50
root.geometry("200x200+{}+{}".format(100, 50))
root.title("root")
root['bg'] = 'green'

tk.Button(root, text='Pop up window2', command=popup_window).pack()

root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.