对于我正在制作的游戏,我需要用户输入数据,并且我想调用一种在GUI上添加一个小的“输入”框的方法(以获取用户名),但是当我尝试这样做时Entry小部件基本上掩盖了所有其他内容并使它们消失。关于为什么会发生或如何解决的任何想法?这是有问题的代码的示例:
root = tkinter.Tk()
root.title('2048')
width = 500
height = 800
root.geometry('%sx%s' % (width,height))
canvas = tkinter.Canvas(root,width=width,height=height,highlightthickness=0)
canvas.pack()
r = canvas.create_rectangle(0,50,50)
canvas.move(r,50)
def keyed(event):
e = tkinter.Entry(canvas)
e.pack()
canvas.bind('<Key>',keyed)
canvas.focus_set()
root.mainloop()