How to get tkinter textbox text after it has been changed?

How to get tkinter textbox text after it has been changed?



Is this the proper time to use a global variable? Should I be using stringVar? What can I do to collect the text after the user has changed it's value?


stringVar



When I add a print(my_msg) statement below the my_msg = sms_textbox.get('1.0', 'end-1c') line in the get_txtmsg() function it will print that the text has changed.


print(my_msg)


my_msg = sms_textbox.get('1.0', 'end-1c')


get_txtmsg()



The same print(my_msg) statement within the askfilename_sms() function returns "Hi, how are you?"


print(my_msg)


askfilename_sms()


"Hi, how are you?"


def askfilename_sms():
print(my_msg)

ent3 = ttk.Labelframe(
tab1, text='New Client Survey SMS')
ent3.grid(
row=3, column=0, sticky=tk.NSEW, padx=2, pady=2)

ttk.Label(
ent3, text='This....n').grid(row=0, column=-0)

def get_txtmsg():
global my_msg
my_msg = sms_textbox.get('1.0', 'end-1c')
askfilename_sms()

my_msg = "Hi, how are you?"

sms_btn = ttk.Button(
ent3, text="Send SMS Surveys",
command=lambda: get_txtmsg())
sms_btn.grid(
row=1, column=1, padx=90, pady=10)
sms_textbox = tk.Text(
ent3, height=6, width=34)
sms_textbox.insert(
'1.0', my_msg)
sms_textbox.grid(
row=0, column=1)



EDIT:



So I am not really sure why this works but I put all the functions into one function and now it works(not thrilled but maybe it is the proper way):


def get_txtmsg():
global my_msg
my_msg = sms_textbox.get('1.0', 'end-1c')
sms_msg_box = tk.messagebox.askyesno(
title='Are you ready to begin?',
message='click to send')
if sms_msg_box:
tk.messagebox.showinfo(
message='Please select New Client Report')
sms_nc_filename = filedialog.askopenfilename(
title="Select New Client file",
filetypes=(("excel files", "*.xls"), ("all files", "*.*")))
if not sms_nc_filename:
return
else:
send_sms.send_survey_text(sms_nc_filename, my_msg)

my_msg = "Hi, how are you"

sms_btn = ttk.Button(
ent3, text="Send SMS Surveys",
command=lambda: get_txtmsg())
sms_btn.grid(
row=1, column=1, padx=90, pady=10)
sms_textbox = tk.Text(
ent3, height=6, width=34)
sms_textbox.insert(
'1.0', my_msg)
sms_textbox.grid(
row=0, column=1)





You can get the text at any time with the get method. It looks like you're already doing that. Why do you think this isn't working? Please provide a Minimal, Complete, and Verifiable example.
– Bryan Oakley
Sep 2 at 23:03


get





Updated the code to be as complete as I can. Should I also create a list so that the data-frame isn't needing to be loaded? It is really difficult to make this code "work" since it has to communicate with an API. Maybe I should cut it down more as a sort of test.
– 6seven8
Sep 2 at 23:11






So when I add a print(my_msg) statement inside the askfilename_sms() it prints the original message.
– 6seven8
Sep 2 at 23:21


print(my_msg)


askfilename_sms()





When I add a print(my_msg) statement after my_msg = sms_textbox.get('1.0', 'end-1c') in the get_txtmsg() function, it does change. So it is somehow changing back in between the 2 steps.
– 6seven8
Sep 2 at 23:24


print(my_msg)


my_msg = sms_textbox.get('1.0', 'end-1c')


get_txtmsg()






Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)