Posts: 30
Threads: 8
Joined: Oct 2025
Mar-01-2026, 06:37 PM
(This post was last modified: Mar-01-2026, 06:37 PM by Tuurbo46.)
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
Posts: 6,981
Threads: 22
Joined: Feb 2020
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?
Posts: 1,301
Threads: 151
Joined: Jul 2017
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()
Posts: 30
Threads: 8
Joined: Oct 2025
(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
Posts: 30
Threads: 8
Joined: Oct 2025
(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
Posts: 6,981
Threads: 22
Joined: Feb 2020
Mar-02-2026, 06:41 PM
(This post was last modified: Mar-02-2026, 06:41 PM by deanhystad.)
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.
Posts: 1,301
Threads: 151
Joined: Jul 2017
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?
Posts: 5
Threads: 0
Joined: Mar 2026
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!
|