You are not logged in.

#1 2012-05-23 18:21:52

xorgx3
Member
From: Poland
Registered: 2011-11-29
Posts: 197

[SOLVED]Python learning and gtk+ try

Hi,
I wanna enjoy with python gtk+ toolkit.
I try run this code:

#!/usr/bin/python
from gi.repository import Gtk
Gtk.init(None)
Hello=Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, "Hello world!")
Hello.format_secondary_text("This is an example dialog.")
Hello.run()

from wiki and I get errors:

Traceback (most recent call last):
  File "./gtk1.py", line 2, in <module>
    from gi.repository import Gtk
  File "/usr/lib/python3.2/site-packages/gi/repository/__init__.py", line 25, in <module>
    from ..importer import DynamicImporter
  File "/usr/lib/python3.2/site-packages/gi/importer.py", line 24, in <module>
    import logging
  File "/usr/lib/python3.2/logging/__init__.py", line 27, in <module>
    from string import Template
ImportError: cannot import name Template

I'm little n00b in python, and I need help smile If it's important I am using geany.


anyway this code in c++ works pretty good.

Last edited by xorgx3 (2012-05-23 19:37:52)

Offline

#2 2012-05-23 18:46:12

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: [SOLVED]Python learning and gtk+ try

I'm a lot n00b in python.  That said, my suggestion would be to try the command that failed (from string import Template) directly in the python interpreter.  If you get the error there, relaunch the interpreter with extra verbosity and run the command again; maybe it will help you figure out what's wrong.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#3 2012-05-23 18:58:13

xorgx3
Member
From: Poland
Registered: 2011-11-29
Posts: 197

Re: [SOLVED]Python learning and gtk+ try

I'm surprised because it working in python interpreter. I don't know why not working in any IDE (geany and eric).

Offline

#4 2012-05-23 19:14:28

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: [SOLVED]Python learning and gtk+ try

@xorgx3: Is there a file named "string.py" in the current directory? If yes, remove it along with "string.pyc" and try again. Otherwise run the script again with "python -v" as suggested by alphaniner.

Offline

#5 2012-05-23 19:21:04

xorgx3
Member
From: Poland
Registered: 2011-11-29
Posts: 197

Re: [SOLVED]Python learning and gtk+ try

Oh, How You know this? Now it working very well. Why this file was a problem?


Anyway very thanks man.

Offline

#6 2012-05-23 19:32:26

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: [SOLVED]Python learning and gtk+ try

To explain lunar's solution:

If you have a python file named string (string.py or string.pyc) in your current directory, python will try to import from that file rather than its proper libraries.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#7 2012-05-23 19:37:35

xorgx3
Member
From: Poland
Registered: 2011-11-29
Posts: 197

Re: [SOLVED]Python learning and gtk+ try

You are great! Very thanks for help!
SOLVED!

Offline

Board footer

Powered by FluxBB