下面顯示的是一個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