Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我要打印代码;。!帆布。!条目“;?_Python_Button_Canvas_Tkinter - Fatal编程技术网

Python 为什么我要打印代码;。!帆布。!条目“;?

Python 为什么我要打印代码;。!帆布。!条目“;?,python,button,canvas,tkinter,Python,Button,Canvas,Tkinter,我不明白发生了什么事。我定义了两个函数。1功能显示文本、输入框和提交按钮。我有它,所以当按下submit按钮时,它会打印用户放在输入框中的信息。为了便于阅读,我缩短了代码 from tkinter import * from PIL import Image, ImageTk canvas_width = 360 canvas_height = 525 file = r"C:\Users\kraak\Desktop\PyCharm Community Edition 2017.1.2\bor

我不明白发生了什么事。我定义了两个函数。1功能显示文本、输入框和提交按钮。我有它,所以当按下submit按钮时,它会打印用户放在输入框中的信息。为了便于阅读,我缩短了代码

from tkinter import *
from PIL import Image, ImageTk


canvas_width = 360
canvas_height = 525
file = r"C:\Users\kraak\Desktop\PyCharm Community Edition 2017.1.2\borderedpaper.GIF"
master = Tk()
canvas = Canvas(master, width=canvas_width, height=canvas_height)

old_img = PhotoImage(file=file)
new_img = old_img.subsample(3, 3)
canvas.create_image(-11, -10, anchor=NW, image=new_img)
canvas.create_window(0, 0, height=1, width=1, anchor=NW)
canvas.create_text(0, 0, text="Test")
e1 = Entry(canvas)

def callback():
    print(e1)

def answer():
    e1 = Entry(canvas)
    canvas.create_window(250, 100, window=e1, height=15, width=100)
    label = Label(text="Enter a word.")
    label.place(x=40, y=90)

    e2 = Entry(canvas)
    canvas.create_window(250, 125, window=e2, height=15, width=100)
    label = Label(text="Enter a word.")
    label.place(x=40, y=115)

    button = Button(text="Submit.", command=callback)
    button.place(x=150, y=460)

answer()
canvas.pack()


mainloop()

因为您正在打印
e1
,这是一个条目。您期望的行为是什么?可能您想要
e1.get()
。我正在尝试从用户获取条目并打印它们。最终,我希望输入框消失,并在画布上显示答案。我现在只是在测试功能。我想我明白了。我把所有的东西都移到了应答函数外,除了最后两行。你的标题暗示它在打印感叹号。真的吗?这似乎不太可能,而且您发布的代码也没有显示感叹号。@BryanOakley我已经在linux中运行了该代码,它确实打印了“!canvas.!entry”。我想小部件的命名方式是特定于平台的。