Skip to content Skip to sidebar Skip to footer

How To Open Multiple Tkinter Windows In One Window

I am having two or more python Tkinter files. Each file is opening one window, how can run all the Tkinter windows functionality in one main window. Ex : I have two files one is u

Solution 1:

You need to designate one script as the main script, and in that one you can import the other. Here's an example of doing this using a simple subclass of the Frame widget:

The primary script (tkA.py):

from Tkinter import *
from tkB import Right # bring in the class Right from secondary scriptclassLeft(Frame):
    '''just a frame widget with a white background'''def__init__(self, parent):
        Frame.__init__(self, parent, width=200, height=200)
        self.config(bg='white')

if __name__ == "__main__":
    # if this script is run, make an instance of the left frame from here# and right right frame from tkB
    root = Tk()
    Left(root).pack(side=LEFT) # instance of Left from this script
    Right(root).pack(side=RIGHT) # instance of Right from secondary script
    root.mainloop()

The secondary script (tkB.py):

from Tkinter import *


classRight(Frame):
    '''just a frame widget with a black background'''def__init__(self, parent):
        Frame.__init__(self, parent, width=200, height=200)
        self.config(bg='black')

if __name__ == "__main__":
    # if this script is run, just do this:
    root = Tk()
    Right(root).pack()
    root.mainloop()

Hope that helps.

Post a Comment for "How To Open Multiple Tkinter Windows In One Window"