Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9134029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:35:22+00:00 2026-06-17T08:35:22+00:00

I want to dynamically create Tkinter windows on my screen. I understand that I

  • 0

I want to dynamically create Tkinter windows on my screen. I understand that I should only have one mainloop(). I use the threading module to make mainloop execute in a seperate thread, so it will not block the script.

How do I create more Tkinter windows after I executed mainloop?

Please take a look at my code:

from Tkinter import *
import threading
import time

class box:
    def __init__(self, pos):
        self.master = Tk()
        self.master.geometry(pos) 
        self.canvas = Canvas(self.master, width=50, height=50, highlightthickness=0 )
        self.canvas.pack()
        self.rect = self.canvas.create_rectangle(0, 0, 50, 50, fill="red", outline="red")
        self.text = self.canvas.create_text(25, 24, text="99",fill="white", font=("calibri", 24, "bold"))

    def changeFill(self, color):
        self.canvas.itemconfig(self.rect, fill=color, outline=color) # change color

class box_manager(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.boxes = {}
        self.add_box(1, "50x50+300+300")
        self.add_box(2, "50x50+100+100")
    def add_box(self, num, pos):
        self.boxes[num] = box(pos)
    def run(self):
        mainloop()

tk = box_manager()
tk.start()

# How do I dynamically add new tkinter windows? the line below makes python.exe crash.
tk.add_box(3, "50x50+200+200")

Update after Joel’s comment, still doesn’t work:

from Tkinter import *
import threading
import time

class MyCustomWindow(Toplevel):
    def __init__(self):
        Toplevel.__init__(self)
        #setup goes here
        self.geometry("50x50+100+100") 
        self.canvas = Canvas(self, width=50, height=50, highlightthickness=0 )
        self.canvas.pack()

class App(Tk):

    def CreateFirst(self):
        self.anotherWindow = MyCustomWindow()
    def CreateSecond(self):
        self.secondWindow = MyCustomWindow()


class SecondWindow(threading.Thread):
    #after 2 seconds create a second window, python.exe crashes
    def run(self):
        time.sleep(2)
        tk.CreateSecond()

SecondWindow().start()
tk = App()
tk.CreateFirst()
mainloop()  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:35:23+00:00Added an answer on June 17, 2026 at 8:35 am

    How do I create more Tkinter windows after I executed mainloop?

    You don’t. That’s not how Tkinter is designed to work. You should always call mainloop exactly once, and from the main thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a hyperlink in asp.net that I want to dynamically create. I
I want to use JavaCompiler to dynamically create some classes. I found the source
i have an array of some values and i want to dynamically create textfields
I want to dynamically create arrays of arrays and I have no clue how
I have a 2d Boolean array and I want to dynamically create it's size
I have a container div inside of which i want to dynamically create other
I have created a button in Expression Blend 4. I want to dynamically create
I want to dynamically create variable names in java el. The problem is that
I want to dynamically create a Drop/Create Script. For that I can calculate the
I have a custom RelativeLayout, where i want to dynamically create Rectangles. They arent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.