0

I'm trying to create a simple gui program in python however when I try to run it I get this error:


This is all I have in code.

from Tkinter import *


test = Tk()

test.title("Reverse")
test.geometry("300 x 200")

test.mainloop()

   'import site' failed; use -v for traceback
        Traceback (most recent call last):
       File "C:/Users/Brenda/PycharmProjects/Reverse a String/Reverse a String.py", line 1, in <module>
        from Tkinter import *
      File "C:\Python27\Lib\lib-tk\Tkinter.py", line 38, in <module>
        import FixTk
      File "C:\Python27\Lib\lib-tk\FixTk.py", line 1, in <module>
        import sys, os
      File "C:\Python27\Lib\os.py", line 398, in <module>
        import UserDict
      File "C:\Python27\Lib\UserDict.py", line 84, in <module>
        _abcoll.MutableMapping.register(IterableUserDict)
      File "C:\Python27\Lib\abc.py", line 109, in register
        if issubclass(subclass, cls):
      File "C:\Python27\Lib\abc.py", line 184, in __subclasscheck__
        cls._abc_negative_cache.add(subclass)
      File "C:\Python27\Lib\_weakrefset.py", line 86, in add
        self.data.add(ref(item, self._remove))
    TypeError: cannot create weak reference to 'classobj' object
Hotshot55
  • 3
  • 1
  • 2
  • in 2.7 you mmay want to try `from tkinter import *` I cant remember but at some point it is lowercase .... annoying i know but maybe thats the issue? what happens if you just do `import os`? – Joran Beasley Jun 26 '14 at 19:23
  • @Joran Beasley in Python2 it is uppercase, in Python3 it is lowercase. – furas Jun 26 '14 at 19:38
  • btw: better don't use space in file name `Reverse a String.py` (and in folder name too) – furas Jun 26 '14 at 19:43

1 Answers1

0
test.geometry("300 x 200") should be: 
test.geometry("300x200")

Also, make sure you are correct in how you installed tkinter. On a linux machine, use:

sudo apt-get install python-tk

You can also try looking at the following similar question: https://stackoverflow.com/q/7753181/3681650

Community
  • 1
  • 1
user3681650
  • 55
  • 1
  • 7
  • After changing test.geometry I'm still getting the same error. Also I'm on windows which I believe the python install includes tkinter with everything else. – Hotshot55 Jun 26 '14 at 22:56
  • Did you incorporate the changes furas referred to? The test.geometry was another issue with your code. – user3681650 Jun 27 '14 at 02:17
  • Open the python interpreter and just type "from Tkinter import *", what is the error that is shown? – user3681650 Jun 29 '14 at 23:41