0

Is it possible to have two instances of tkinter ?

import tkinter as tk
import tkinter as sk

root = tk.Tk()
root2 = sk.Tk()

....some window with tk

....some window with sk
root.mainloop()
root2.mainloop()

then have a Toplevel() in both instances.

1
  • 1
    You shouldn't. And you definitely don't need to import the module twice with a different alias. Why do you need two?
    – scotty3785
    Aug 19 at 20:19

1 Answer 1

3

You can, but the way it works likely won't be like what you expect. Importing it twice isn't the problem (but neither is it the solution). No matter how you import it or how often you import it, creating more than one instance of Tk is the problem. Each instance is backed by a separate internal interpreter. Images and variables and widgets created in one won't exist in the other.

If you need more than one window, it's usually best if second and subsequent windows are instances of Toplevel.

Not the answer you're looking for? Browse other questions tagged or ask your own question.