I am learning python tkinter but I have an error whenever I tried to compile it:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/
widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/jason/.spyder2/.temp.py", line 14, in <module>
menu.config(menu=menu)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1274,
inconfigure
return self._configure('configure', cnf, kw)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1265,
in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown option "-menu").
My code is:
from tkinter import *
def hello():
print "hello"
root = Tk()
menu = Menu(root)
menu.config(menu=menu)
menu.add_command(label ="new",command = hello)
root.mainloop()
You have an issue with your code a little bit. Instead of menu.config, use root.config, you will not get any such errors.
For more information and detailed tutorial, kindly visit Tkinter Menu Widget.
Related
I have a simple class created with the editor pycharm . I want to initiate several objects with different input in the ipython console and check how different objects of the class type behaves. Is it even possible to do it in the console ? I am ending up with the following error:
rect = Rectangle(5,4)
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-
packages/IPython/core/interactiveshell.py", line 2883, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-14-48f6e104f766>", line 1, in <module>
rect = Rectangle(5,4)
NameError: name 'Rectangle' is not defined
I must have missed something in the process.
--------EDIT------------------
I tried the the very same thing at Spyder editor without importing anything there and it works fine there.
Did you mean -
import Rectangle
I tried it as well and then I got the following error:
import Rectangle
Traceback (most recent call last):
File "/usr/lib/python2.7/dist -
packages/IPython/core/interactiveshell.py", line 2883, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-15-6878d2e924f4>", line 1, in <module>
import Rectangle
File "/home/sajjad/Hämtningar/programvara/PyCharm/pycharm-community-2017.1/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named Rectangle
---------EDIT1------------------
import os
print os.getcwd()
/home/sajjad/PycharmProjects/PyQt/book/chap03
And the Rectangle.py is within the above directory.
I am using the Blessed library to build a simple terminal application.
My application builds upon the following simple example for a dumb editor: https://github.com/jquast/blessed/blob/master/bin/editor.py
Warning: the following steps will break your IPython, and I don't know how to fix it!
For the purposes of this question, I'll just use editor.py. Let's make a couple of changes to allow debugging:
1) import ipdb
2) put in ipdb.set_trace() on line 224
Run editor.py now: python editor.py. The following error should be produced:
Traceback (most recent call last):
File "editor.py", line 14, in <module>
from manager import Manager
File "/home/abcd/python_scripts/editor.py", line 25, in <module>
import ipdb
File "/usr/local/lib/python2.7/dist-packages/ipdb/__init__.py", line 7, in <module>
from ipdb.__main__ import set_trace, post_mortem, pm, run, runcall, runeval, launch_ipdb_on_exception
File "/usr/local/lib/python2.7/dist-packages/ipdb/__main__.py", line 47, in <module>
ipapp.initialize([])
File "<decorator-gen-110>", line 2, in initialize
File "/usr/lib/python2.7/dist-packages/IPython/config/application.py", line 92, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/IPython/terminal/ipapp.py", line 332, in initialize
self.init_shell()
File "/usr/lib/python2.7/dist-packages/IPython/terminal/ipapp.py", line 348, in init_shell
ipython_dir=self.ipython_dir, user_ns=self.user_ns)
File "/usr/lib/python2.7/dist-packages/IPython/config/configurable.py", line 354, in instance
inst = cls(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/IPython/terminal/interactiveshell.py", line 328, in __init__
**kwargs
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 483, in __init__
self.init_readline()
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 1843, in init_readline
self.readline_startup_hook = readline.set_startup_hook
AttributeError: 'module' object has no attribute 'set_startup_hook'
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev#scipy.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
c.Application.verbose_crash=True
Now, whenever one runs IPython by executing the ipython command, this error will be produced:
Traceback (most recent call last):
File "/usr/bin/ipython", line 5, in <module>
start_ipython()
File "/usr/lib/python2.7/dist-packages/IPython/__init__.py", line 120, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/usr/lib/python2.7/dist-packages/IPython/config/application.py", line 564, in launch_instance
app.initialize(argv)
File "<decorator-gen-110>", line 2, in initialize
File "/usr/lib/python2.7/dist-packages/IPython/config/application.py", line 92, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/IPython/terminal/ipapp.py", line 332, in initialize
self.init_shell()
File "/usr/lib/python2.7/dist-packages/IPython/terminal/ipapp.py", line 348, in init_shell
ipython_dir=self.ipython_dir, user_ns=self.user_ns)
File "/usr/lib/python2.7/dist-packages/IPython/config/configurable.py", line 354, in instance
inst = cls(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/IPython/terminal/interactiveshell.py", line 328, in __init__
**kwargs
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 483, in __init__
self.init_readline()
File "/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 1843, in init_readline
self.readline_startup_hook = readline.set_startup_hook
AttributeError: 'module' object has no attribute 'set_startup_hook'
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev#scipy.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
c.Application.verbose_crash=True
So, IPython seems to be globally broken. I have gotten this issue on both Cygwin and Ubuntu.
What's going wrong?
I am a beginner in programming, started from Python. I learn by Dr Charles Severance materials. So in his book there is an example:
import urllib
fhand = urllib.urlopen('http://www.py4inf.com/code/rom...
for line in fhand:
print line.strip()
When I copy paste it to Python 2 version (I use PyCharm 5.0.4) there appears:
Traceback (most recent call last):
File "D:/Python4yk/temprehg111.py", line 2, in <module>
fhand = urllib.urlopen('http://www.py4inf.com/code/rom...
File "C:\Python27\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 208, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 292, in open_http
import httplib
File "C:\Python27\lib\httplib.py", line 79, in <module>
import mimetools
File "C:\Python27\lib\mimetools.py", line 6, in <module>
import tempfile
File "C:\Python27\lib\tempfile.py", line 35, in <module>
from random import Random as _Random
File "random.py", line 3, in <module>
integers
NameError: name 'line' is not defined
When I type another example, gets an error also. What is wrong? I don`t even write a program. I just copy paste an example. Asked Dr Chuck - still no answer.
Try this:
import urllib
fhand = urllib.urlopen('http://www.py4inf.com')
for line in fhand:
print line.strip() # notice the indentation
I recently installed panda3d version 1.8.1 which was termed as latest stable release.But when I typed the following code
from direct.showbase.ShowBase import ShowBase
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
app = MyApp()
app.run()
The above code generated the following error message :
:ShowBase(warning): Unable to open 'onscreen' window.
Traceback (most recent call last):
File "D:\delme.py", line 8, in <module>
app = MyApp()
File "D:\delme.py", line 6, in __init__
ShowBase.__init__(self)
File "C:\Panda3D-1.8.1\direct\showbase\ShowBase.py", line 244, in __init__
self.openDefaultWindow(startDirect = False, props=props)
File "C:\Panda3D-1.8.1\direct\showbase\ShowBase.py", line 880, in openDefaultWindow
self.openMainWindow(*args, **kw)
File "C:\Panda3D-1.8.1\direct\showbase\ShowBase.py", line 916, in openMainWindow
self.openWindow(*args, **kw)
File "C:\Panda3D-1.8.1\direct\showbase\ShowBase.py", line 671, in openWindow
raise StandardError, 'Could not open window.'
StandardError: Could not open window.
Any ideas why is this happening and how do I resolve it??
I solved the problem myself.
I edited panda3d1.8.1/etc/config.txt
I changed : load-display pandadx9
to : load-display p3tinydisplay
When i running my code I am getting following error saying ImportError: No module named ext
Code sample causing error
import module.model
module.model.dropdb(input)
module.model.createdb(input)
The trace back as follows
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "module/models/__init__.py", line 54, in drop_db
drop_db_with_migrations(quiet)
File "module/models/__init__.py", line 31, in drop_db_with_migrations
from module.app import db
File "module/app.py", line 42, in <module>
app.jinja_env.add_extension('hamlpy.ext.HamlPyExtension')
File "/vagrant-dev/opt/dev_virtualenv/local/lib/python2.7/site-packages/Jinja2
-2.6-py2.7.egg/jinja2/environment.py", line 288, in add_extension
self.extensions.update(load_extensions(self, [extension]))
File "/vagrant-dev/opt/dev_virtualenv/local/lib/python2.7/site-packages/Jinja2
-2.6-py2.7.egg/jinja2/environment.py", line 75, in load_extensions
extension = import_string(extension)
File "/vagrant-dev/opt/dev_virtualenv/local/lib/python2.7/site-packages/Jinja2
-2.6-py2.7.egg/jinja2/utils.py", line 213, in import_string
return getattr(__import__(module, None, None, [obj]), obj)
ImportError: No module named ext
Your problem is in your Traceback:
Traceback (most recent call last):
-- SNIP --
File "module/app.py", line 42, in <module>
app.jinja_env.add_extension('hamlpy.ext.HamlPyExtension')
-- SNIP --
ImportError: No module named ext
Jinja2 uses the dunder import mechanism __import__(some_package_name_string). It's unable to find a subpackage ext in your hamlpy package.