Python Forum
Multiple Instances of Tkinter GUI Opening
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple Instances of Tkinter GUI Opening
#1
Hello,

I have written a Tkinter GUI in Python Spyder 6.1.3. However, when I run the GUI in Spyder two instances of the GUI open (when I close the GUI two instances are open). How do I overcome this problem?

Many thanks,

Tuurbo46
Reply
#2
When you run the script from a shell you only get one window?

Why do you care? You won’t normally run your gui from Spider, will you?
Reply
#3
Run myApp() in Spyder. How many windows do you get?

import tkinter as tk
from tkinter import ttk

def myApp():
    root = tk.Tk(className='Not Bed Fellows')
    root.geometry('500x400')
    root['background']='yellow'  # pretty!
    frm = ttk.Frame(root, padding=10)
    frm.grid()
    style = ttk.Style()
    style.theme_use('alt')
    style.configure('TButton', background = 'red', foreground = 'white', width = 20, borderwidth=1, focusthickness=3, focuscolor='none')
    style.map('TButton', background=[('active','red')])
    ttk.Label(frm, text="Hello World!").grid(column=0, row=0)
    ttk.Label(frm, text="Goodbye World!").grid(column=1, row=1)
    ttk.Button(frm, text="Close this window",  command=root.destroy).grid(column=2, row=2)
    root.mainloop()
Reply
#4
(Mar-02-2026, 01:45 AM)Pedroski55 Wrote: Run myApp() in Spyder. How many windows do you get?

import tkinter as tk
from tkinter import ttk

def myApp():
    root = tk.Tk(className='Not Bed Fellows')
    root.geometry('500x400')
    root['background']='yellow'  # pretty!
    frm = ttk.Frame(root, padding=10)
    frm.grid()
    style = ttk.Style()
    style.theme_use('alt')
    style.configure('TButton', background = 'red', foreground = 'white', width = 20, borderwidth=1, focusthickness=3, focuscolor='none')
    style.map('TButton', background=[('active','red')])
    ttk.Label(frm, text="Hello World!").grid(column=0, row=0)
    ttk.Label(frm, text="Goodbye World!").grid(column=1, row=1)
    ttk.Button(frm, text="Close this window",  command=root.destroy).grid(column=2, row=2)
    root.mainloop()

Hello Pedroski55,

I have copied your code into Spyder and selected 'run cell' and no window pops up. I just get the below output:

%runcell -i 0 C:/Users/admin/.spyder-py3/test.py

Not sure what I am doing wrong?

Cheers
Reply
#5
(Mar-01-2026, 10:23 PM)deanhystad Wrote: When you run the script from a shell you only get one window?

Why do you care? You won’t normally run your gui from Spider, will you?

Hello deanhystad,

I am quite new to Python and I haven't done this part before.

So I have gone to the 'Command Prompt' and typed in the path to 'test.py' and it opens in Spyder:

C:\Users\admin>.spyder-py3\test.py

I have searched for 'Python 3.13' but I cannot see it installed on the C drive? It takes me to the Microsoft store. If I download this, will it overwrite / corrupt my current Spyder install?

Could you kindly explain what I should do to properly run this script?

Thanks,
Tuurbo46
Reply
#6
If you want to write tkinter programs, why are you using Anaconda and spyder? I've read that Spyder and tkinter don't get along well. Google "using tkinter in spyder" for a description of why. From most of the posts I see on the topic, your problem is not common. The common problem is no windows appear.
Reply
#7
I'm guessing no windows is worse than 2 windows?

Try starting Idle?

Not sure how to do that in Windows, but in Linux you can start Idle from a bash shell easily:

Quote:peterr@peterr-Modern-15-B7M:~$ python3 -m idlelib.idle

Up pops an Idle shell window, you can try out your code there. Press ctrl and n to get a new window, save your code there.

import the modules you need into the Idle shell window, one at a time:

import tkinter as tk
from tkinter import ttk
Copy and paste myApp() into the Idle shell window, then enter myApp(). Works fine for me!

But, of course, you should be using a Virtual Environment. Look up: How to set up a Virtual Environment in Python?
Reply
#8
Hi there,

It sounds like you're facing an issue with multiple instances of your Tkinter GUI opening. This usually happens when you create more than one root window (Tk()), which causes new windows to open unexpectedly.
Hi there! I’m a Python enthusiast passionate about building projects and solving coding challenges. Currently, I’m exploring ways to integrate Python with new tools and platforms. One of the interesting tools I've come across recently is the link removed, which helps with streamlined media browsing and management. If anyone has experience using it with Python, feel free to share your insights!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Using SQLAlchemy, prevent SQLite3 table update by multiple program instances Calab 2 2,370 Aug-09-2023, 05:51 PM
Last Post: Calab
  Multiprocessing Pool Multiple Instances How to Kill by Pool ID sunny9495 0 1,958 Nov-16-2022, 05:57 AM
Last Post: sunny9495
  Python: re.findall to find multiple instances don't work but search worked Secret 1 2,571 Aug-30-2022, 08:40 PM
Last Post: deanhystad
  How to work with multiple files and tkinter? philipbergwerf 3 7,408 Aug-31-2020, 12:03 PM
Last Post: ndc85430
  opening a file from a windows desktop folder- error opening file Charan007 1 4,114 Dec-06-2018, 11:50 AM
Last Post: buran
  multiple instances kerzol81 2 58,044 Aug-01-2018, 09:34 AM
Last Post: DeaD_EyE
  Multiple and dynamic windows confusion in Tkinter bertibott 1 5,160 Mar-15-2017, 07:51 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020