How do I place a preset into the text box?
Steve
Gronicus at SGA.Ninja
Fri Aug 28 15:51:34 EDT 2020
Yes, the form/window now closes properly.
Removal of sys.exit() and inserting window.destroy() cleared up the exiting
problem.
Thanks.
I saw several variations on that but I guess I just never twerked it enough.
Footnote:
"What rhymes with orange?"
"No it doesn't.."
From: Colin McPhail <colin.mcphail at mac.com>
Sent: Friday, August 28, 2020 7:46 AM
To: Chris Narkiewicz via Python-list <python-list at python.org>
Cc: Steve <Gronicus at SGA.Ninja>
Subject: Re: How do I place a preset into the text box?
Hi Steve,
On 28 Aug 2020, at 11:03, Steve <Gronicus at SGA.Ninja
<mailto:Gronicus at SGA.Ninja> > wrote:
The following program compiles but does not quite do what I would like it to
do. Line 19 is the preset information but I do not seem to be able to get it
into the form by code. My purpose is to let the user make changes without
having to re-enter the entire code.
I'm no Tk expert but does the following do what you want? (Strictly
speaking, the parentheses in ("1234-abcd") are not wrong just unnecessary.)
#===========================================================
import tkinter as tk
from tkinter import ttk
import sys
window = tk.Tk()
window.title("Python Tkinter Text Box")
window.minsize(600,400)
def Submit():
label.configure(text= 'The new code is: ' + NewCode.get())
def ClickExit():
#This exit closes the program but the form remains and is still active.
# I want only to close the form.
print("Exiting")
#sys.exit()
window.destroy()
#OldCode = ("1234-abcd")
OldCode = "1234-abcd"
label = ttk.Label(window, text = "Enter the new code")
label.grid(column = 1, row = 1)
#NewCode = tk.StringVar()
NewCode = tk.StringVar(value=OldCode)
CodeEntered = ttk.Entry(window, width = 15, textvariable = NewCode)
CodeEntered.grid(column = 2, row = 3)
button = ttk.Button(window, text = "Submit", command = Submit)
button.grid(column= 2, row = 5)
button = ttk.Button(window, text = "Quit", command = ClickExit)
button.grid(column= 2, row = 7)
window.mainloop()
x = (NewCode.get())
print("The new code entered is: " + x)
#=================================================
Regards,
Colin
More information about the Python-list
mailing list