Only using grid Tkinter but still getting TclError - python

So I just started using Google Colab and I keep getting this error:
TclError: cannot use geometry manager grid inside . which already has slaves managed by pack
I'm trying to make a GUI window that takes in the information from the user and saves it.
Everything I've read online says that the issue is that I'm using pack() and grid(), but I'm only using grid(). The error starts when I first try to place my labels (sourceLabel).
I'm so confused, any help would be great.
try: # In order to be able to import tkinter for
import tkinter as tk # either in python 2 or in python 3
from tkinter import *
except ImportError:
import Tkinter as tk
from Tkinter import *
#creates window
window = tk.Tk()
window.title("File Information")
window.rowconfigure([0,1], minsize=30)
window.columnconfigure([0, 1, 2, 3], minsize=30)
#this program opens the file with information and adds the new information to it
def saveInfo():
value = path.get()
loc = source.get()
recode = recoding.get()
#change name of file and will this make them see everything
#f = open("./info.txt", "a+")
#f.write("Source Data File Location: " + loc + ", Complete File Path: " + value + ", Is recoding of column names and/or values desired?: " + recode)
#f.flush()
#f.seek(0)
#content = f.read()
#print (content)
finalList = [value,loc,recode]
#f.close()
window.withdraw()
print (finalList)
return finalList
#creates a text label, fg=foreground and bg=background, theyre the locations of colors, width and height are measured by text units which are separate horizonatal and vertical
sourceLabel = tk.Label(
text="Source Data File Location:",
width = 21,
height=2)
#adds text to window
sourceLabel.grid(row=0,column=0)
#creates second label
pathLabel = tk.Label(
text="Complete File Path:",
width = 20,
height=2)
#adds text to window
pathLabel.grid(row=1,column=0)
#creates third label
sourceLabel = tk.Label(
text="Is recoding of column \n names and/or values \n desired:",
width = 20,
height=4)
#adds text to window
sourceLabel.grid(row=2,column=0)
#create dropdown for sources
source = StringVar(window)
source.set("Local") # default value
sourceOption = OptionMenu(window, source, "Local", "Google Drive", "One Drive")
sourceOption.grid(row=0,column=1,sticky="ew")
#adds path entry
path = tk.Entry(fg="black", bg="white", width=35)
#adds path to window
path.grid(row=1,column=1,sticky="ew")
#create dropdown for recoding
recoding = StringVar(window)
recoding.set("Yes") # default value
recodingOption = OptionMenu(window, recoding, "Yes", "No")
recodingOption.grid(row=2,column=1,sticky="new")
#creates the click to save button
button = tk.Button(
text="Click to Save",
width=10,
height=1,
bg="white",
fg="black", command=saveInfo
)
#adds Button to window
button.grid(row=4,column=1,sticky="w")
#runs window
window.mainloop()
window.destroy()

This is a very weird error you had here, I just re-wrote your code using the canvas and pack method, instead of a grid, rows, and columns. Just make sure you are using Python3x Just so none of these weird bugs resurface, hope this helps, you can play around with the x and y values at the bottom, and you can mess with the height and width values at the top when we set the canvas. Happy coding!
from tkinter import *
global path, source, recoding # Global Values so that save_info can get the values
# Creates window
root = Tk()
root.title("File Information")
# Canvas Creates the base layer for the window, so instead of l = Label(text="Test").grid(row=2, column=3)
# We would now do l = Label(text="Test")
# canvas.create_window(20, 30, anchor="nw", window=l)
canvas = Canvas(width=400, height=300)
canvas.pack(fill="both", expand=True)
# Canvas.pack() just finishes creating the canvas.
# This program opens the file with information and adds the new information to it.
def save_info():
global path, source, recoding
value = path.get()
loc = source.get()
recode = recoding.get()
# change name of file and will this make them see everything
# f = open("./info.txt", "a+")
# f.write("Source Data File Location: " + loc + ", Complete File Path: " + value + ", Is recoding of column names and/or values desired?: " + recode)
# f.flush()
# f.seek(0)
# content = f.read()
# print (content)
finalList = [value, loc, recode]
# f.close()
root.withdraw()
print(finalList)
return finalList
sourceLabel = Label(
text="Source Data File Location:",
width=21,
height=2)
pathLabel = Label(
text="Complete File Path:",
width=20,
height=2)
recoding_label = Label(
text="Is recoding of column \n names and/or values \n desired:",
width=20,
height=4)
source = StringVar(root)
source.set("Local") # default value
sourceOption = OptionMenu(root, source, "Local", "Google Drive", "One Drive")
path = Entry(fg="black", bg="white", width=35)
recoding = StringVar(root)
recoding.set("Yes") # default value
recodingOption = OptionMenu(root, recoding, "Yes", "No")
button = Button(
text="Click to Save",
width=10,
height=1,
bg="white",
fg="black", command=save_info
)
# Since we are now using canvas, we must add all the elements using canvas.create_window, the first int is the x value, 2nd is the y
# Just leave anchor always as nw, and windows need to equal the variable of the widget they need to add
canvas.create_window(0, 50, anchor="nw", window=sourceLabel)
canvas.create_window(0, 90, anchor="nw", window=pathLabel)
canvas.create_window(0, 140, anchor="nw", window=recoding_label)
canvas.create_window(150, 50, anchor="nw", window=sourceOption)
canvas.create_window(150, 90, anchor="nw", window=path)
canvas.create_window(150, 140, anchor="nw", window=recodingOption)
canvas.create_window(150, 225, anchor="nw", window=button)
root.mainloop()
# I refactored some of the variables so they would be unique

Related

Update text widget in tkinter from function

The problem:
I am trying to update the same text widget box from a function that contains some text. Instead a whole new text window appears every time.
Here is my code:
from tkinter import *
import os
#Tkinter graphics
homepage = Tk()
homepage.title("My first GUI")
# set size of window
homepage.geometry('1200x400')
# Add image file
bg = PhotoImage(file = "maxresdefault.png")
# Show image using label
label1 = Label( homepage, image = bg)
label1.place(x = 0, y = 0)
label2 = Label( homepage, text = "Test App")
label2.pack()
# Create Frame
frame1 = Frame(homepage)
frame1.pack()
#button initatiors
def buttonupdate():
S = Scrollbar(homepage)
T = Text(homepage, height=100, width=30)
T.pack()
T.pack(side=RIGHT, fill= Y)
S.pack(side = RIGHT, fill = Y)
S.config(command=T.yview)
T.insert(END, "test")
T.config(yscrollcommand=S.set, state=DISABLED)
# Static buttons
tickets30button = Button(text = "This is button 1", command=buttonupdate)
tickets30button.place(x=0, y=26)
mcibutton = Button(text = "This is button 2")
mcibutton.place(x=0, y=52)
hdebutton = Button(text = "This is button 3")
hdebutton.place(x=0, y=78)
homepage.mainloop()
Here is the result if I click on the first button three times:
Let me know if you have any suggestions that I can try.
Thank you for your time,
I was able to update my text window instead of create a new one, upon each click of a button, thanks to #TheLizzard.
He mentioned to move the section of code that creates the text window outside of the function and keep the section of code that creates the text, inside the function.
Before:
#button initiators
def buttonupdate():
S = Scrollbar(homepage)
T = Text(homepage, height=100, width=30)
T.pack()
T.pack(side=RIGHT, fill= Y)
S.pack(side = RIGHT, fill = Y)
S.config(command=T.yview)
T.insert(END, "test")
T.config(yscrollcommand=S.set, state=DISABLED)
After: (UPDATED)
S = Scrollbar(homepage)
T = Text(homepage, height=100, width=30)
T.pack(side=RIGHT, fill= Y)
S.pack(side = RIGHT, fill = Y)
S.config(command=T.yview)
T.config(yscrollcommand=S.set, state=DISABLED)
#button initatiors
def myTicketstatusbutton():
T.delete(1.0,END)
T.insert(END, "test")

_tkinter.TclError: bad window path name ".!checkbutton"

I am trying to create an app that finds certain fields from a checkbox list.
I am stuck at self.text.window_create("end", window=cb) while calling search function. Although it works fine when running the line in the __init__ it throws an error here.
import tkinter as tk
class App:
def search(self):
searched_field = self.search_box.get()
found_indexes = []
for i in range(len(self.name_list)):
if searched_field in self.name_list[i]:
found_indexes.append(i)
self.text.delete("1.0", "end")
for i in range(len(found_indexes)):
cb = self.check_buttons[found_indexes[i]]
self.text.window_create("end", window=cb)
self.text.insert("end", "\n")
def write_names(self):
name_file = "names.txt"
with open(name_file, "w") as file:
for name in self.returned_list:
file.write(name + "\n")
def __init__(self, root, name_list):
self.check_buttons = []
self.var_list = []
self.returned_list = []
self.name_list = name_list
self.start = 0
self.search_box = tk.Entry(root)
self.search_box.pack(side="top")
self.search_button = tk.Button(root, text='Search', command=self.search)
self.search_button.pack()
self.scroll_bar = tk.Scrollbar(orient="vertical")
self.text = tk.Text(root, width=20, height=10, yscrollcommand=self.scroll_bar.set)
self.scroll_bar.config(command=self.text.yview)
self.scroll_bar.pack(side="right", anchor="ne", fill="y")
self.text.pack(side="top", fill="both", expand=True)
for name in name_list:
var = tk.BooleanVar()
cb = tk.Checkbutton(text=name, padx=0, pady=0, bd=0, variable=var)
self.check_buttons.append(cb)
self.var_list.append(var)
for cb in self.check_buttons:
self.text.window_create("end", window=cb)
self.text.insert("end", "\n")
tk.Button(root, text='Write names', command=self.write_names()).pack()
tk.Button(root, text='Quit', command=root.quit).pack()
name_list = ["aaa", "bbbb", "cccc", "abcd"]
root = tk.Tk()
app = App(root, name_list)
root.mainloop()
Error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\RO100162\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/RO100162/Desktop/proiect/eoIUPS/scrollbar.py", line 19, in search
self.text.window_create("end", window=cb)
File "C:\Users\RO100162\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 3423, in window_create
+ self._options(cnf, kw))
_tkinter.TclError: bad window path name ".!checkbutton"
You need to pass in the tkinter root
cb = tk.Checkbutton(root, text=name, padx=0, pady=0, bd=0, variable=var)
Similar to your other buttons
self.search_button = tk.Button(root, text='Search', command=self.search)
When you delete the contents of the text widget, that causes the checkbuttons to be deleted as well.
This is from the official tcl/tk documentation on the text widget [1]:
The embedded window's position on the screen will be updated as the text is modified or scrolled, and it will be mapped and unmapped as it moves into and out of the visible area of the text widget. Each embedded window occupies one unit's worth of index space in the text widget, and it may be referred to either by the name of its embedded window or by its position in the widget's index space. If the range of text containing the embedded window is deleted then the window is destroyed. Similarly if the text widget as a whole is deleted, then the window is destroyed.

import error no module named tkinter issue for latest Python version 3.8.2

I have been trying to resolve the error:
ImportError: No module named tkinter
however no solutions from previous questions seem to be working at all.
I have tried :
sudo apt-get install python3-tk
and tkinter installed successfully, yet the issue remains.
I've tried making the t in tkinter uppercase as i'm using Python 3.8.2 yet that did not work.
I have also tried reinstalling/repairing Python as tkinter supposedly comes with the latest Python versions.
Attempting to open my file with python3 main.py results in the following error
Traceback (most recent call last):
File "main.py", line 95, in
window = Tk()
File "/usr/lib/python3.6/tkinter/init.py", line 2023, in init
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
I have also tried installing tkinter through its installer for
Windows, the installer works yet I still have the same issue. I have also tried updating my pip. Running pip list does not display tkinter.
Below is my main.py file.
from tkinter import *
from tkinter import filedialog
from tkinter.ttk import Progressbar
import tkinter.font as font
import os.path
from modify_data_pandas import get_column_headings
from modify_data_pandas import scan_file
#Closes window
def close_window():
window.destroy()
#Function checks if the file exists, changes label
def is_valid(*args):
if os.path.isfile(input_file_path.get()):
valid_confirm_lbl.config(text="File Found!")
valid_confirm_lbl.config(fg="green")
return 1
else:
valid_confirm_lbl.config(text="File Not Found")
valid_confirm_lbl.config(fg="red")
return 0
#Sets progress bar value
def setbar(value):
progress_bar['value'] = value
#Gets the current selection in the list box
def add_selection():
if is_valid():
items = headers_listbox.curselection()
already_selected = headers_listbox_selected.get(0, END)
for item in items:
if headers[item] not in already_selected:
headers_listbox_selected.insert(END, headers[item])
#Gets the current selection in the list box
def remove_selection():
if is_valid():
items = headers_listbox_selected.curselection()
pos = 0
for i in items :
idx = int(i) - pos
headers_listbox_selected.delete(idx,idx)
pos = pos + 1
#Add all items in listbox to selection
def add_all():
if is_valid():
items = headers_listbox.get(0, END)
for item in items:
if item not in headers_listbox_selected.get(0, END):
headers_listbox_selected.insert(END, item)
#Remove all items in selection listbox
def remove_all():
if is_valid():
headers_listbox_selected.delete(0, END)
#Scans the file for sensitive data
def scan():
if is_valid():
print("Scan")
change_row, change_col, change_type = scan_file(input_file_path, headers_listbox_selected.get(0, END))
#Anonymizes the file
def anonymize():
if is_valid():
print("do anonymize")
#Opens file dialog to pick a csv file
def choose_file():
input_file_name = filedialog.askopenfilename(initialdir = "/", title = "Select file",filetypes = (("CSV files","*.csv"),))
input_file.delete(0, END)
input_file.insert(END, input_file_name)
#Analyzes the file for sensitive data
def analyze_file():
if is_valid():
headers_listbox.delete(0, END)
headers_listbox_selected.delete(0, END)
global headers
headers = get_column_headings(input_file_path)
#headers = list of column headings from selected file
for item in headers:
headers_listbox.insert(END, item)
#Call function that checks each cell for sensitive data
return 1
else:
return 0
#Configure GUI Window
window = Tk()
window.title("CSV Anonymizer")
window.geometry("413x800")
lbl_frame = Frame(window)
lbl_frame.grid(column=0, row=1)
listbox_lbl_frame = Frame(window)
listbox_lbl_frame.grid(column=0, row=5, pady=5)
listbox_frame = Frame(window)
listbox_frame.grid(column=0, row=6)
listbox_btn_frame = Frame(window)
listbox_btn_frame.grid(column=0, row=7)
listbox_btn_frame_2 = Frame(window)
listbox_btn_frame_2.grid(column=0, row=8)
#Label: "File:"
input_file_prompt = Label(lbl_frame, text="File:",anchor=W, justify=LEFT)
input_file_prompt.pack(side = LEFT)
input_file_prompt.config(width=20)
#Label: "File Not Found / File Found!"
valid_confirm_lbl = Label(lbl_frame, text="", anchor=E, justify=RIGHT)
valid_confirm_lbl.pack(side = RIGHT)
valid_confirm_lbl.config(width=20)
#Create stringvar so file path is verified upon change
input_file_path = StringVar()
#Text Field to display/enter Input File Name
input_file = Entry(window, textvariable=input_file_path, width=10)
input_file.grid(column=0, row=2, padx=20)
input_file.config(width=40)
#Checks if the file is valid upon change
input_file_path.trace_add("write", is_valid)
#Button: "Click to Select a File", opens file browser to select a file
choose_file_btn = Button(window, text = "Click to Select a File", command = choose_file)
select_btn_font = font.Font(family='Helvetica', size=20, weight='bold')
choose_file_btn['font'] = select_btn_font
choose_file_btn.grid(column = 0, row = 0, padx=20, pady=20)
choose_file_btn.config(height=3,width=30)
#Button: "Use This File", starts analyze_file func
use_file_btn = Button(window, text = "Use This File", command = analyze_file)
use_file_btn.grid(column = 0, row = 3, padx=20, pady=(8, 10))
use_file_btn.config(width=13, height=2)
#Label "Select the columns you would like to anonymize"
select_columns_lbl = Label(window, text="Select the columns you would like to anonymize")
bold_font = font.Font(family='Helvetica', size=15, weight='bold')
select_columns_lbl['font'] = bold_font
select_columns_lbl.grid(column=0, row=4)
select_columns_lbl.config(width=40)
#Labels state listbox titles
column_headings_lbl = Label(listbox_lbl_frame, text = "Column Headings")
column_headings_lbl.pack(side=LEFT)
column_headings_lbl.config(width=20)
selected_column_headings_lbl = Label(listbox_lbl_frame, text = "Selected")
selected_column_headings_lbl.pack(side=RIGHT)
selected_column_headings_lbl.config(width=20)
#Left listbox, shows column headings from selected file
headers_listbox = Listbox(listbox_frame, selectmode = MULTIPLE)
headers_listbox.pack(side=LEFT)
headers_listbox.config(width=20)
#Right listbox, shows selected column headings
headers_listbox_selected = Listbox(listbox_frame, selectmode = MULTIPLE)
headers_listbox_selected.pack(side=RIGHT)
headers_listbox_selected.config(width=20)
#Buttons to add and remove current selections from respective listboxes
add_selection_btn = Button(listbox_btn_frame, text = "Add Current Selection", command = add_selection)
add_selection_btn.pack(side=LEFT)
add_selection_btn.config(width=20)
remove_selection_btn = Button(listbox_btn_frame, text = "Remove Current Selection", command = remove_selection)
remove_selection_btn.pack(side=RIGHT)
remove_selection_btn.config(width=20)
#Buttons to add and remove all items from their respective listboxes
add_all_btn = Button(listbox_btn_frame_2, text = "Add All", command = add_all)
add_all_btn.pack(side=LEFT)
add_all_btn.config(width=20)
remove_all_btn = Button(listbox_btn_frame_2, text = "Remove All", command = remove_all)
remove_all_btn.pack(side=RIGHT)
remove_all_btn.config(width=20)
#Label "Select the columns you would like to anonymize"
get_suggestions_lbl = Label(window, text="Would you like to scan the file for sensitive data?")
get_suggestions_lbl['font'] = bold_font
get_suggestions_lbl.grid(column=0, row=9, pady=(15, 10))
get_suggestions_lbl.config(width=40)
#Button: "Scan File", starts scan_file func
get_suggestions_btn = Button(window, text = "Scan File", command = scan)
get_suggestions_btn.grid(column = 0, row = 10, pady=(0, 10))
get_suggestions_btn.config(width=20, height=2)
#Button: "Anonymize", starts anonymize func
anonymize_btn = Button(window, text = "Anonymize", command = anonymize)
anonymize_btn.grid(column = 0, row = 11, pady=(0, 10))
anonymize_btn.config(width=20, height=2)
progress_bar = Progressbar(window, orient = 'horizontal', length = 286, mode = 'determinate')
progress_bar.grid(column = 0, row = 12, pady =2)
progress_bar["maximum"] = 100
progress_bar["value"] = 0
#Button to quit the program
quit_btn = Button(window, text = "Quit", command = close_window)
quit_btn.grid(column = 0, row = 20)
quit_btn.config(width=10, height=2)
window.mainloop()
Any ideas?

Python Tkinter entry-point

So for a project on my school I am trying to make an GUI where I can add some info for some email so it will send it automatically through an python script.
Now I do have a small problem. I made some entry-points but for some reason I can not add text to the left of the entr-ypoints. Does anyone know how to do that?
I am trying to get 'sending to:', 'name:', and 'course:' to the left of the corresponding entry-points.
It might sounds silly, but please do not change to much of the actual code. It has to be like this for the project.
Kind regards,
Allard
import os
import smtplib
import tkinter as tk
root =tk.Tk()
root.title("Title")
def main():
USER = os.environ.get('USERNAME_GMAIL')
PASSWORD = os.environ.get('PASSWORD_GMAIL')
print("-"*60)
print("\nNew Email\n\n")
with smtplib.SMTP('smtp.gmail.com',587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login(USER, PASSWORD)
PROFESSOR = entry2.get()
COURSE = entry3.get()
subject = 'Course literature: ' + COURSE
body = 'Body of the email, doesnt really matter whats in here' + PROFESSOR
msg= f'Subject:{subject}\n\n{body} '
smtp.sendmail(USER, RECEIVER, msg)
canvas1 = tk.Canvas(root, height=400, width= 400)
canvas1.pack()
entry1=tk.Entry(root)
canvas1.create_window(200, 60, window=entry1)
entry2=tk.Entry(root)
canvas1.create_window(200, 80, window=entry2)
entry3=tk.Entry(root)
canvas1.create_window(200, 100, window=entry3)
def PRINT():
x1 = entry1.get()
x2 = entry2.get()
x3 = entry3.get()
label1= tk.Label(root, text = 'Sending to: ' + str(x1))
canvas1.create_window(200,200, window=label1)
label2= tk.Label(root, text = 'Name: '+ str(x2))
canvas1.create_window(200,220, window=label2)
label3= tk.Label(root, text = 'Course: ' +str(x3))
canvas1.create_window(200,240, window=label3)
button1 = tk.Button(text = 'TEST', bg="black", fg="white", font=('helvetica', 9, 'bold'), command=PRINT)
canvas1.create_window(200,130, window=button1)
button2 = tk.Button(text = 'Verzenden via email', bg = "red", fg= "white", font=('helvetica', 9, 'bold'), command=main)
canvas1.create_window(200,160, window=button2)
You should not be trying to place widgets at exact coordinates. Tkinter has managers for handling layout in a logical manner: pack and grid. These take care of problems with different window sizes, different resolutions, and different fonts, and are superior to placing elements at specific x/y coordinates.
Since you want to create a grid of label/entry pairs, grid is the correct choice.
entry1=tk.Entry(root)
entry2=tk.Entry(root)
entry3=tk.Entry(root)
label1 = tk.Label(root, text="Sending to:")
label2 = tk.Label(root, text="Name:")
label3 = tk.Label(root, text="Course:")
label1.grid(row=0, column=0)
entry1.grid(row=0, column=1)
label2.grid(row=1, column=0)
entry2.grid(row=1, column=1)
label3.grid(row=2 column=0)
entry3.grid(row=2, column=1)
You need to save the item ID of each canvas1.create_window(...) and then use the item ID to find the position of the entry and put a text before the entry using canvas1.create_text(...):
...
# function to put a prompt before the 'entry' item
def create_prompt(prompt, entry):
# get the bounding box of the Entry item
bbox = canvas1.bbox(entry)
# create a canvas text item and put it before the Entry item like below:
# (x-5,y) (x,y)
# -------+ +-----------------+
# prompt: | Entry |
# +-----------------+
#
# note that bbox[0] is the x-coordinate of the top-left of entry item
# bbox[1] is the y-coordinate of the top-left of entry item
# using anchor='ne' means that the (x, y) of the text is the top-right corner of the text
# and finally return the item ID of the canvas text item
return canvas1.create_text(bbox[0]-5, bbox[1], text=prompt, anchor='ne')
entry1=tk.Entry(root)
entry1_item = canvas1.create_window(200, 60, window=entry1)
create_prompt('sending to:', entry1_item)
entry2=tk.Entry(root)
entry2_item = canvas1.create_window(200, 80, window=entry2)
create_prompt('name:', entry2_item)
entry3=tk.Entry(root)
entry3_item = canvas1.create_window(200, 100, window=entry3)
create_prompt('course:', entry3_item)
...

Refresh my tkinter label and lets it overwrite it with different output content

I have a Submit button that prints the output on the tkinter widget label. Everytime I change the input and click the Submit the output is displayed but not at the same place i.e. The previous content of the label is not overwritten.
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()
A 'refresh' button that would clear the Label of its content and lets you overwrite it.
I am taking your function ImageVerification() as a blackbox and assuming it is working.
The reason this is happening is because you create a new Label, whenever the Submit button is pressed. What you have to do is to create the display Label outside the function and configure its text, whenever the button is pressed. Something like this.
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)

Categories