I've been working with the same Python/Tkinter code for a week now, and seemingly out of nowhere I am getting the error "Bad label specification":
Traceback (most recent call last):
File "C:/Users/shapirju/Desktop/NumericalAnalysis-Project2/gui.py", line 1188, in <module>
gui = App()
File "C:/Users/shapirju/Desktop/NumericalAnalysis-Project2/gui.py", line 62, in __init__
self.createWidgets()
File "C:/Users/shapirju/Desktop/NumericalAnalysis-Project2/gui.py", line 70, in createWidgets
self.interpLabelframe = LabelFrame(self.root, text = "Interpolation", labelanchor=N)
File "C:\Program Files\Python27\lib\lib-tk\ttk.py", line 776, in __init__
Widget.__init__(self, master, "ttk::labelframe", kw)
File "C:\Program Files\Python27\lib\lib-tk\ttk.py", line 555, in __init__
Tkinter.Widget.__init__(self, master, widgetname, kw=kw)
File "C:\Program Files\Python27\lib\lib-tk\Tkinter.py", line 2096, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: Bad label anchor specification 443664640LN
It is caused by the line self.interpLabelframe = LabelFrame(self.root, text = "Interpolation", labelanchor=N)
As this worked a few hours ago, maybe this is an environmental issue? I cannot find anything about this issue on Google.
Changing it to self.interpLabelframe = LabelFrame(self.root, text = "Interpolation", labelanchor='n') fixes the issue.
According to the source code for LabelFrame, the label anchors are defined as strings 'n', 'we', etc.
Related
I created GUI in Python (Python2.7) using Tkinter. I wish to have it up and running for both RHEL7.4 and RHEL5.11 versions. On REHL7.4, it works fine but on RHEL5.11, it gives the following error:
Traceback (most recent call last):
File "configure_workstation.py", line 28, in <module>
app = ConfigureWorkstation(wsObj)
File "/tmp/hnoman/v0.62/ConfigureWorkstation.py", line 90, in __init__
frame = F(self.fMenu, self)
File "/tmp/hnoman/v0.62/WorkstationInfoMenu.py", line 35, in __init__
self.generateHostnameFrame()
File "/tmp/hnoman/v0.62/WorkstationInfoMenu.py", line 50, in generateHostnameFrame
self.oLocation = ttk.OptionMenu(self.fHostname, self.location, dict[1], *dict.values())
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 1591, in __init__
Menubutton.__init__(self, master, **kw)
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 797, in __init__
Widget.__init__(self, master, "ttk::menubutton", kw)
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 554, in __init__
_load_tile(master)
File "/usr/local/python27/lib/python2.7/lib-tk/ttk.py", line 46, in _load_tile
master.tk.eval('package require tile') # TclError may be raised here
_tkinter.TclError: can't find package tile
Can someone guide how to overcome this?
This is my code:
from tkinter import *
logoImage = PhotoImage(file='logo.png')
logoLabel = Label(root, image=logoImage, bg='dodgerblue3')
logoLabel.grid(row=0, column=0)
The image is in the same directory as the project. In fact, when I open it with cmd or Python it works. But when I use VS Code or Turn it into .exe file, it shows this error:
Traceback (most recent call last):
File "c:\Users\Simo\OneDrive\Python\Scientific calculator\calc.py", line 180, in <module>
logoImage = PhotoImage(file='logo.png')
File "C:\Users\Simo\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4093, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Simo\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4038, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "logo.png": no such file or directory
How can I fix this?
Maybe try putting the file into your workspace and using the relative path.
I am trying to insert an image to window but I get an error.
Traceback (most recent call last):
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 1549, in __call__
return self.func(*args)
File "C:\Users\Afro\Desktop\h.py", line 151, in start
pic_lab = Label(wind,image=pik)
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2605, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2138, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage2" doesn't exist
Here's my code
wind = Tk()
name = money.jpg'
pik = ImageTk.PhotoImage(Image.open(name))
pic_lab = Label(wind,image=pik)
pic_lab.grid()
What do I need to do?
The string 'money.jpg' that is assigned to the variable name is missing a single quotation mark on the left.
I am trying to draw an image onto a canvas (mid conversion from place to canvas) and this error appears
hastebin containing code:
http://hastebin.com/tuciyisisa.py
Traceback (most recent call last):
File "D:\Stuff\python\Coursework\AQADo\main.py", line 82, in <module>
app = Application(master=root)
File "D:\Stuff\python\Coursework\AQADo\main.py", line 74, in __init__
self.drawCounter(space_y, current_space, game_canvas)
File "D:\Stuff\python\Coursework\AQADo\main.py", line 26, in drawCounter
canvas.create_image(170, space_y[current_space["1a"]], counter1)
File "C:\Python34\lib\tkinter\__init__.py", line 2291, in create_image
return self._create('image', args, kw)
File "C:\Python34\lib\tkinter\__init__.py", line 2282, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: unknown option "pyimage2"
canvas.create_image(170, space_y[current_space["1a"]], counter1)
There seems to be a problem with your function signature here. create_image expects a position tuple, plus keyword arguments. Try:
canvas.create_image((170, space_y[current_space["1a"]]), image=counter1)
Now your application runs without any apparent errors.
I tried to run this simple program on python 2.5 and get the following error, I am not sure what is going on.
Code:
import pylab
pylab.figure(1) # make figure 1 the current figure
pylab.plot([1,2,3,4], [1,7,3,5]) # draw on figure 1
pylab.show() # show figure on screen
Error:
Traceback (most recent call last):
File "/Users/sebastiancarrasco/Desktop/Courses/6.00.2x/Week1/plotting-seg1.py", line 3, in <module>
pylab.figure(1) # make figure 1 the current figure
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pyplot.py", line 270, in figure
**kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 85, in new_figure_manager
figManager = FigureManagerTkAgg(canvas, num, window)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 403, in __init__
self.toolbar = NavigationToolbar2TkAgg( canvas, self.window )
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 670, in __init__
NavigationToolbar2.__init__(self, canvas)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backend_bases.py", line 2273, in __init__
self._init_toolbar()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 719, in _init_toolbar
command=self.home)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 702, in _Button
im = Tk.PhotoImage(master=self, file=file)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", line 3294, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", line 3250, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't open "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/mpl-data/images/home.ppm": permission denied
For anyone else who runs into this problem and comes across this page: I eventually found the answer here. Long story short: some problem with the installer messes up the permissions for all the files in the "images" folder. All you have to do is change the permissions to give yourself read privileges.