Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/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_User Interface_Tkinter - Fatal编程技术网

Python 刷新我的tkinter标签,让它用不同的输出内容覆盖它

Python 刷新我的tkinter标签,让它用不同的输出内容覆盖它,python,user-interface,tkinter,Python,User Interface,Tkinter,我有一个提交按钮,它在tkinter小部件标签上打印输出。每次我更改输入并单击“提交”按钮时,都会显示输出,但不在同一位置,即不会覆盖标签的先前内容 from tkinter import * from tkinter import filedialog root = Tk() root.title("ImageValidation ") root.geometry("600x600+100+100") pathlist = [None, None] # holds the two fil

我有一个提交按钮,它在tkinter小部件标签上打印输出。每次我更改输入并单击“提交”按钮时,都会显示输出,但不在同一位置,即不会覆盖标签的先前内容

from tkinter import *
from tkinter import filedialog

root = Tk()
root.title("ImageValidation ")
root.geometry("600x600+100+100")

pathlist = [None, None]  # holds the two files selected
labels = []

def browse_button(index):

    global filename
    filename =  filedialog.askopenfilename(title = "Choose your file",filetypes = (("jpeg files","*.jpeg"),("all files","*.*")))
    pathlist[index] = filename

heading = Label(root, text = "Select 2 images you want to Validate", 
font=("arial",15,"bold","underline"), fg="blue").pack()

label1 = Label(root, text = "Enter Image 1", font=("arial",10,"bold"), 
fg="black").place(x=10, y = 100)
label2 = Label(root, text = "Enter Image 2", font=("arial",10,"bold"), 
fg="black").place(x=10, y = 200)

button = Button(root,text="Choose an Sign1",width = 30,command= lambda: 
browse_button(0)).place(x=250, y= 100)
button =  Button(root,text="Choose an Sign2",width = 30,command= 
lambda: browse_button(1)).place(x=250, y= 200)

def display():

    ImageVerification(pathlist[0], pathlist[1])

    l1 = Label(root,text=Scriptoutput, width = 200 )
    l1.pack(side='bottom', padx=50, pady=50)
    #Scriptoutput is the output variable from the main code.

submit_button = Button(text="Submit", width=15,command = display)
submit_button.pack(side='bottom', padx=15, pady=15)

root.mainloop() 

一个“刷新”按钮,可以清除其内容的标签并允许您覆盖它。

我将您的函数
ImageVerification()
视为一个黑盒,并假设它正在工作

发生这种情况的原因是,每当按下Submit按钮时,您都会创建一个新标签。只要按下按钮,就必须在函数外部创建显示标签并配置其文本。像这样的

l1 = Label(root, text="", width=200)
l1.pack(side='bottom', padx=50, pady=50)

def display():
    ImageVerification(pathlist[0], pathlist[1])

    l1.configure(text=Scriptoutput)
    #Scriptoutput is the output variable from the main code.

submit_button = Button(text="Submit", width=15,command = display)
submit_button.pack(side='bottom', padx=15, pady=15)

ImageVerification()
做什么?它检查两个图像是否匹配。如果匹配,则在标签l1中使用的“Scriptoutput”变量中显示“Matched”。因此,当我选择2个新图像文件n点击提交时,显示消息不会覆盖上一个,而是显示在小部件的其他位置@Miraj50你以前也发过类似的问题,我已经回答了。太好了!!非常感谢。@Ramandepsing不客气。如果它对你有帮助,请考虑接受它。