Reputation: 49
I need help on this. I'm just started to learn Tkinter and I have some difficulties to do this:
Image: Main window with a new window
Basically, what I want is to do is to create a frame in the main window (root or master) that pop-out initially. This frame will contain labels and buttons; besides, it will be above other labels and buttons. Similar to the image I posted. I tried to achieve this by creating a new window but the new window comes with title, minimize, maximize and close button which it is something I do not want. I want to achieve I similar result like the image I posted. Thank you in advance.
Upvotes: 0
Views: 896
Reputation: 386342
If you do not need a floating window, you can just create a frame and use place
to place it in the center of the window.
Here's a basic example:
import tkinter as tk
class Popout(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent, background="black", padx=10, pady=10)
title = tk.Label(self, text="How to play", font=("Helvetica", 16), anchor="w",
background="black", foreground="white")
instructions = tk.Label(self, text="The goal of Klondike is to blah blah blah...",
background="black", foreground="white", anchor="w")
cb = tk.Checkbutton(self, text="Do not show again", highlightthickness=0,
background="black", foreground="white")
oneof = tk.Label(self, text="1 of 6", background="black", foreground="white")
close_btn = tk.Button(self, text="Close", background="black", foreground="white")
next_btn = tk.Button(self, text="Next", background="black", foreground="white")
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(1, weight=1)
title.grid(row=0, column=0, columnspan=2, sticky="ew")
oneof.grid(row=0, column=2, sticky="ne")
instructions.grid(row=1, column=0, columnspan=3, sticky="nsew", pady=10)
cb.grid(row=2, column=0, sticky="w")
close_btn.grid(row=3, column=1, sticky="ew", padx=10)
next_btn.grid(row=3, column=2, sticky="ew")
root = tk.Tk()
root.geometry("600x400")
p = Popout(root)
p.place(relx=.5, rely=.5, anchor="center")
root.mainloop()
Upvotes: 2