Tkinter语法错误,位于“文本=”某些随机文本”处

问题描述 投票:0回答:1

我是编程新手,从python和Tkinter开始。我在线上观看了本教程视频,并且在尝试理解它的同时,编写的代码与本教程中的家伙完全一样。但是,我收到语法错误,无法运行。 screenshot

[很抱歉,这是我的第一篇文章。好的,这是代码:

from tkinter import *

#key down function
def click():
    entered_text=textentry.get() #this will collect the text from the text entry box
    output.delete(0,0, END)
    try:
        definition = my_compdictionary[entered_text]
    except:
        definition = "Sorry there is no word like that , try again"
        output.insert(END, definition)
#MAIN
window = Tk()
window.title("My computer Science Glosarry")
#MY PHOTO
photo1 = PhotoImage(file="C:/Users/zahar/Desktop/photo2.gif")
Label (window, image=photo1, bg="black") .grid(row=0, column=0, sticky=E)
# create label
Label = (window, text="Enter a word you would like a definition for:", bg="black", fg="white", font="none 12 bold") .grid(row1, column=0, sticky=W)
python tkinter syntax
1个回答
0
投票

您错过了一些东西:)

Label1 = tk.Label(window..)
#####^use Label1 instead of Label, cause you cold overwrite the tk class

from tkinter import *

#key down function
def click():
    entered_text=textentry.get() #this will collect the text from the text entry box
    output.delete(0,0, END)
    try:
        definition = my_compdictionary[entered_text]
    except:
        definition = "Sorry there is no word like that , try again"
        output.insert(END, definition)
#MAIN
window = Tk()
window.title("My computer Science Glosarry")
#MY PHOTO
photo1 = PhotoImage(file="C:/Users/zahar/Desktop/photo2.gif")
Label(window, image=photo1, bg="black").grid(row=0, column=0, sticky=E)
# create label
Label(window, text="Enter a word you would like a definition for:", bg="black", fg="white", font="none 12 bold").grid(row1, column=0, sticky=W)
######^ here is the syntax error
###### either you do Label(window...)
###### or you sign a variable to the label like Label1 = Label(window...)
© www.soinside.com 2019 - 2024. All rights reserved.