Обновите мою метку tkinter и дайте ей перезаписать другой выводимый контент - PullRequest
0 голосов
/ 10 января 2019

У меня есть кнопка Submit, которая печатает вывод на ярлыке виджета 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() 

Кнопка «Обновить», которая удаляет метку ее содержимого и позволяет перезаписать ее.

1 Ответ

0 голосов
/ 10 января 2019

Я принимаю вашу функцию ImageVerification() как черный ящик и предполагаю, что она работает.

Причина, по которой это происходит, заключается в том, что вы создаете новую метку при каждом нажатии кнопки «Отправить». Вам нужно создать метку дисплея вне функции и настроить ее текст при каждом нажатии кнопки. Как то так.

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)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...