tkinter.Text() error (_tkinter.TclError : expected integer, got “sans”)


tkinter.Text() error (_tkinter.TclError : expected integer, got “sans”)



I get this error from tkinter.Text():


tkinter.Text()


>>> import tkinter
>>> tkinter.Text()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/tkinter/__init__.py", line 3095, in __init__
Widget.__init__(self, master, 'text', cnf, kw)
File "/usr/lib/python3.6/tkinter/__init__.py", line 2293, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: expected integer but got "sans"



or even tkinter._test() :


tkinter._test()


>>> tkinter._test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/tkinter/__init__.py", line 3985, in _test
label = Label(root, text=text)
File "/usr/lib/python3.6/tkinter/__init__.py", line 2760, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "/usr/lib/python3.6/tkinter/__init__.py", line 2293, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: expected integer but got "sans"



The message is pretty clear, but I don't know where to start.



EDIT : I got this error when I tried to use matplotlib.pyplot.plot(). But this worked (no error anymore) for matplotlib. I didn't find a similar way to deal with tkinter.


matplotlib.pyplot.plot()


matplotlib


tkinter




1 Answer
1



I am not getting any kind of error with the same code, so I can't debug it. So, I think you should try the following:


from tkinter import *
root=Tk()
log = Text(root, state='disabled', width=80, height=24, wrap='none')
log.grid()
root.mainloop()



If it doesn't work and other widgets like, buttons and entries don't work then there is something wrong with the tkinter that you have installed. So, try to unistall and then, reinstall tkinter:


sudo apt-get remove python3-tk
sudo apt-get install python3-tk



If the above gives an error,use this link to check for your your version of linux, how to do it (refer to the comments also) :
Install tkinter for Python



Try it and let me know if that helps.





I get the same error message, as soon as I call Text(), even with no argument.
– Thibaut
Jun 26 at 12:02





Do the buttons or entries work?
– Eshita Shukla
Jun 28 at 10:34





Button() and Entry() don't work either, same error.
– Thibaut
Jun 28 at 17:19





The widgets that do not send this error are Canvas, Frame, OptionMenu, PanedWindow, Scrollbar, Toplevel (the ones that don't need text I suppose).
– Thibaut
Jun 28 at 17:28






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Render GeoTiff to on browser with leaflet

How to get chrome logged in user's email id through website

using states in a react-navigation without redux