Tkinter在“text=”一些随机文本“处出现语法错误

2024-10-04 05:30:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我是编程新手,从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)

Tags: the代码textfromoutput教程windowlabel
1条回答
网友
1楼 · 发布于 2024-10-04 05:30:37

你错过了什么:)

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...)

相关问题 更多 >