导入时出现 Tkinter 错误 [英] Tkinter error with importing
本文介绍了导入时出现 Tkinter 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 python 中创建一个简单的 gui 程序,但是当我尝试运行它时出现此错误:
I'm trying to create a simple gui program in python however when I try to run it I get this error:
这是我所有的代码.
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
推荐答案
test.geometry("300 x 200") should be:
test.geometry("300x200")
另外,请确保您安装 tkinter 的方式是正确的.在 Linux 机器上,使用:
Also, make sure you are correct in how you installed tkinter. On a linux machine, use:
sudo apt-get install python-tk
您也可以尝试查看以下类似问题:https://stackoverflow.com/q/7753181/3681650
You can also try looking at the following similar question: https://stackoverflow.com/q/7753181/3681650
这篇关于导入时出现 Tkinter 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文