【发布时间】:2019-01-06 17:00:09
【问题描述】:
无论我使用什么方法导入 tkinter,Python3 都会给我这个或其他错误。
我在网上搜索了我的问题的解决方案,但没有一个有效。我正在运行最新版本的 Ubuntu。
#!/usr/bin/env python3
from tkinter import *
def main():
main_window = tkinter.Tk()
main_window.title("free communism here")
click_function = print("WEWE")
communism_button = tkinter.button(text = "click for free communism", command = click_function, height = 40, width = 120)
communism_button.pack()
tkinter.mainloop()
main()
结果是:
Traceback (most recent call last):
File "communism button.py", line 10, in <module>
main()
File "communism button.py", line 4, in main
main_window = tkinter.Tk()
NameError: name 'tkinter' is not defined.
我无法弄清楚程序为什么不起作用。它应该显示一个按钮,如果你按下它,它应该显示“WEWE”。对不起我可能糟糕的英语。
【问题讨论】:
-
您从命名空间 tkinter 导入了所有名称,而不是命名空间本身。删除 tkinter。 maniloop() 应该是 main_window.mainloop。
标签: python-3.x tkinter