2

I keep on encountering problems with Tkinter in spyder and I am unsure why. Repeatedly I'd spent a lot of time trying to fix code in spyder which is fully operational in IDLE. Is there a simple reason for this? Is my code wrong and IDLE is ignoring the incorrect bits while spyder is having an issue. When running the code there is never an error in spyder it just doesn't operate as expected. I will show some code that displays differently in IDLE than it does spyder.

from tkinter import font
import tkinter as tk

root = tk.Tk()
root.title("N Body Simulation")
root.geometry('400x300')

frame = tk.Frame(root)
frame.pack()

# titlefont = font.Font(family="Lucida Grande",size=45)
titlefont = font.Font(family='Helvetica', name='titlefont', size=50, weight='bold')
text_intro = "N-Body Simulation"
title = tk.Label(root, text=text_intro, font=titlefont)
title.place(relx=0.5, rely=0.1, anchor="center")
    
root.mainloop()

The image on the top is from spyder and the one on the bottom is IDLE. Why does it keep appearing different, and what am I doing wrong. To me, I have done the necessary steps to change the font size and make it bold. Also is there a way to run it like IDLE but though spyder, sorry if that last part is a silly question. Thanks in advance.

Spyder

IDLE

Harry Spratt
  • 179
  • 11
  • 1
    I have no idea what might be causing the problem but if you remove the `app = FullScreenApp(root)`, does the problem persist? If the problem is still there, you can simplify the code by removing the whole class. Otherwise it will tell you that it might have something to do with the class (unlikely in my opinion). – TheLizzard Jul 09 '21 at 20:12
  • Sorry, I know it wasn't the minimal example but sometimes I found the Tkinter frame doesn't appear properly without it. I have now removed it but the problem persists. I have updated the code accordingly. – Harry Spratt Jul 09 '21 at 20:19
  • even `spyder` may have bugs. – furas Jul 09 '21 at 20:47
  • `idle` and `spyder` may use different version of Python and it seems one of them has problem with fonts. You could check `print( sys.executable )` to see if both use the same Python. – furas Jul 09 '21 at 20:50
  • how do you run it? Code should run without `FullScreenApp` - and this `FullScreenApp` gives me error message when I run it in normal way `python script.py` becuse this `FullScreenApp` doesn't exists in normal situation. Maybe this `FullScreenApp` changes everything and this makes your problem. – furas Jul 09 '21 at 20:53
  • IDLE works from /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 and spyder works from /opt/anaconda3/bin/python but I don't know what the works for me – Harry Spratt Jul 09 '21 at 21:00
  • my bad about the FullScreenApp I was meant to delete all the code relating to that so, therefore, an error popped up. I have now gotten rid of all the code relating. The code above still works in IDLE but not spyder. – Harry Spratt Jul 09 '21 at 21:02
  • 1
    @HarrySpratt Can you please tell me the output of `print(tk.TclVersion)` from both `IDLE` and `spyder`? `tcl` is a library that `tkinter` heavily uses. – TheLizzard Jul 09 '21 at 21:15
  • They are both running 8.6 – Harry Spratt Jul 09 '21 at 21:20
  • After searching on the internet a bit I found [this](https://stackoverflow.com/questions/47769187/make-anacondas-tkinter-aware-of-system-fonts-or-install-new-fonts-for-anaconda). No idea if it will work because I don't use `spyder` – TheLizzard Jul 09 '21 at 21:25
  • 1
    '8.6' covers round 10 years of releases of tcl/tk. The python.org installer installs with 3.9 a customized build of 8.6.8. In spyder, try rook.tk.call('info', 'patchlevel'). If earlier than 8.6.8, it has more bugs on macOS than 8.6.8. 3.10 included 8.6.11, which has more patches for macOS. – Terry Jan Reedy Jul 09 '21 at 23:47
  • From spyder, the output yields 8.6.10 and from IDLE the output is 8.6.8. Apologies for the late reply. – Harry Spratt Jul 11 '21 at 13:29

0 Answers0