Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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 Tkinter覆盖文本_Python_Tkinter - Fatal编程技术网

Python Tkinter覆盖文本

Python Tkinter覆盖文本,python,tkinter,Python,Tkinter,我正在学习Tkinter,我有点困惑。 下面的代码显示了face\u recognition()函数中的白色文本 import tkinter as tk from PIL import Image, ImageTk from facerec_on_raspberry_pi import face_function #face_function() return recognized person name root = tk.Tk() #Fullscreen root.overridere

我正在学习Tkinter,我有点困惑。 下面的代码显示了
face\u recognition()
函数中的白色文本

import tkinter as tk
from PIL import Image, ImageTk
from facerec_on_raspberry_pi import face_function #face_function() return recognized person name

root = tk.Tk()

#Fullscreen
root.overrideredirect(True)
root.overrideredirect(False)
root.attributes('-fullscreen',True)
root.configure(background='black')

def my_mainloop():
    print (face_function())
    instructions = tk.Label(root, text=str(face_function()), font=('Raleway', 55), fg='white', bg='black')
    instructions.place(x=160, y=60)
    root.after(1, my_mainloop)

root.after(1, my_mainloop)

root.mainloop()

但文本是重叠的。在显示新文本之前如何清理它

以下是正在发生的事情的图像:

这是一个不知名的人和巴拉克·奥巴马的叠加-

这里是无人和未知的人叠加。

无需每次更改文本时都重新创建标签。创建后可以更改现有标签的文本。还要注意我评论的两行:你不需要两个都要

import tkinter as tk
from PIL import Image, ImageTk
from facerec_on_raspberry_pi import face_function #face_function() return recognized person name

root = tk.Tk()

#Fullscreen
root.overrideredirect(True) # Use only one of this two lines: 
root.overrideredirect(False) # you just set a flag and then change it
root.attributes('-fullscreen',True)
root.configure(background='black')

instructions = tk.Label(root, text='', font=('Raleway', 55), fg='white', bg='black')
instructions.place(x=160, y=60)

def my_mainloop():
    print (face_function())
    instructions['text'] = str(face_function())    
    root.after(1, my_mainloop)

root.after(1, my_mainloop)

root.mainloop()

您不需要每次需要更改文本时都重新创建标签。创建后可以更改现有标签的文本。还要注意我评论的两行:你不需要两个都要

import tkinter as tk
from PIL import Image, ImageTk
from facerec_on_raspberry_pi import face_function #face_function() return recognized person name

root = tk.Tk()

#Fullscreen
root.overrideredirect(True) # Use only one of this two lines: 
root.overrideredirect(False) # you just set a flag and then change it
root.attributes('-fullscreen',True)
root.configure(background='black')

instructions = tk.Label(root, text='', font=('Raleway', 55), fg='white', bg='black')
instructions.place(x=160, y=60)

def my_mainloop():
    print (face_function())
    instructions['text'] = str(face_function())    
    root.after(1, my_mainloop)

root.after(1, my_mainloop)

root.mainloop()

您真的需要覆盖多个标签吗?为什么不重复使用同一个标签呢?您可以在函数外部创建标签,然后执行标签['text']='newtext'。告诉我是否合适,我会发布完整的答案。是的,这对我很有用,我不需要多个标签。你能发布一个完整的答案吗?谢谢,你真的需要覆盖多个标签吗?为什么不重复使用同一个标签呢?您可以在函数外部创建标签,然后执行标签['text']='newtext'。告诉我是否合适,我会发布完整的答案。是的,这对我很有用,我不需要多个标签。你能发布一个完整的答案吗?谢谢,太棒了,这很有效。非常感谢:)太棒了,这很有效。非常感谢:)