I have a variable that is updated on a button click, and I want to show the variable's value in a Text widget, but I'm getting a blank every time despite checking that the variable is not empty.
I'm using a StringVar called var as a middle man but the result is still blank.
from tkinter import *
import time
var = None
def get_tags():
tag_info={'hashtags':"Loading..."}
var.set(str(tag_info.get('hashtags','')))
if __name__ == '__main__':
root = Tk()
root.title("Tag Generator")
var = StringVar(root)
show_button = Button(root, text='Show',
command=lambda: get_tags())
show_button.grid(column=2,columnspan=1, padx=5, pady=5, row=num+1)
result_text = Text(root)
result_text.grid(column=0,columnspan=3, padx=5, pady=5, row=num+2, rowspan=4)
result_text.insert('1.0',var.get())
while True:
time.sleep(0.01)
root.update()
How can I show the contents of var in my Text widget?
EDIT:contents of my var variable:
var.get()
Out[86]: '.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n#cat #dog #catsofinstagram #cats #pet #dogsofinstagram #catlover #cute #love #dogs #pets #catstagram #instagood #puppy #kitty #animals #petstagram #dogstagram #gato #kitten #animal #instadog #catoftheday #doglover #cats_of_instagram #adorable #instagram #dogoftheday #instacat #meow '
(which is as expected/desired)
var.get()is adding text into theTextwidget it could've to do withtag_infotry printing it to the console and check if it has any value or not?var.get()run alone seems fine, I edited my question to demonstratevar. I will edit my question accordingly and humbly beg your forgiveness