2

I Have used Python Tkinter Is There a Way to use multiple windows in tkinter Can Any one tell pe Please

0

3 Answers 3

5

You can use tk.Toplevel() to create new window in tkinter.

More information is available here

Example

new_win=Toplevel()

Note: if you destroy the main Tk() all of the Toplevel() attached to that main window will also be destroyed.

Sign up to request clarification or add additional context in comments.

1 Comment

It might be worth adding a comment that says something like: if you destroy the main Tk() all of the Toplevel()s attacked to that main window will also be destroyed.
3

I believe an example is in order.

import tkinter as tk

# primary tkinter window
parent = tk.Tk()
parent.title( "Parent" )

# A child window can be created like so
child = tk.Toplevel( parent )
child.transient( parent )
child.title( "Child" )

# Note the reference to parent when child is created
# The transient method will guarantee the child will ALWAYS be in front of the parent
# Any number of children can be created for every parent

# Complex widgets that have many components require time to instantiate correctly
parent.update_idletasks()

# When a parent is destroyed so will the children

def closer( event ):
    parent.destroy()

# Widgets can be bound to keyboard or mouse inputs
parent.bind( "<Escape>", closer )

parent.mainloop()

7 Comments

The parent.update_idletasks() is useless. All of the things it will do will be done when the code execution reaches parent.mainloop().
@TheLizzard the rem statement mentions complex widgets.
What widget would need that? All widgets that are part of tkinter and tkinter.ttk don't need .update_idletasks() to be created correctly. Also can you give an example of a complex widget?
Something with lots of images, scrollbars, children, buttons etc...
Still doesn't need .update_idletasks(). If you have spare time can you please give me a basic minimal example (on something like pastebin) where removing the .update_idletasks() will be a problem? Also the documentation never mentions that it initialises the widget/children of that widget.
|
1

You can have multiple instance of Tk() -

root = Tk()
win = Tk()

But multiple instances of Tk() are discouraged, see why

The best solution is Top Levels This is how you make a toplevel widget -

toplevel = Toplevel(root, bg, fg, bd, height, width, font, ..)

2 Comments

Windows and tabs have different meanings right? So I thought OP wanted multiple windows and not tabs
But OP mentions windows

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.