下面显示的是一个Tkinter的登录窗口中的代码,我试图得到一个标志,以显示在屏幕的顶部,但得到这个错误,当这样做:全局名称tkinter未定义?
NameError: global name 'tkinter' is not defined
这里是我完整的代码:
*原代码在这里
感谢
代码后EDIT(移除Tkinter的):
from tkinter import *
root = Tk()
root.title("Speed Wars Login")
def createInterface():
Label(root, text="Log in").grid(row=1, column=0)
Label(root, text="Create Account").grid(row=1, column=3)
#PLACE IMAGE
canvas = Canvas(root)
canvas.grid(row=0, column=2)
photo = PhotoImage(file = "logo.gif")
canvas.create_image(0, 0, image=photo)
Label(root, text="Username").grid(row=2, column=0)
Label(root, text="Password").grid(row=3, column=0)
global usrnm
global psswrd
usrnm = Entry(root, width = 15)
psswrd = Entry(root, show="*", width = 15)
usrnm.grid(row=2, column=1)
psswrd.grid(row=3, column=1)
def loginprint():
print("Username: %s\nPassword: %s" % (usrnm.get(), psswrd.get()))
createInterface()
Button(root, text="Login", command = loginprint).grid(row=3, column=0)
root.mainloop()
你用'*'导入了'tkinter'中的所有东西。因此你不需要做'tkinter.something'。仅供参考,使用'from module import *'不是很好的做法。 – DavidG
我会尽力的,谢谢! – RossC
查看[this](https://stackoverflow.com/questions/710551/import-module-or-from-module-import)问题/回答不同的方式导入模块及其优点/缺点 – DavidG