from tkinter import *
from PIL import Image, ImageTk
import datetime
import os
root = Tk()
root.title("To-do List")
root.geometry("400x600")
root.resizable(width=False, height=False)
# Balance
global be
bet = settings_main_canvas.create_text(110, 165, text="Balance: ", font="Helvetica 14") # Balance Entry Text
be = Entry(root, width=20, font="Helvetica 10", borderwidth=2, bg="#f0f0f0") # Balance Entry
be.insert(0, "Amount in USD")
settings_main_canvas.create_window(170, 165, window=be, anchor=W)
# Text
global acc_name
global balance
global progress_bar_tasks
acc_name = sidebar_canvas.create_text(65, 18, text=ane.get(), font="TimesNewRoman 10 bold", anchor=NW)
balance = sidebar_canvas.create_text(65, 35, text=be.get() "$", font="TimesNewRoman 8", anchor=NW)
progress_bar_tasks = sidebar_canvas.create_text(180, 30, text="{} / {} Complete".format(len(inbox_finished_tasks), len(inbox_tasks_num)), font="TimesNewRoman 9", anchor=NW)
root.mainloop()
I don't know why but when I print be.get()
it always returns the value that I inserted, even though I changed the text in the entry
CodePudding user response:
The reason this happens is, before you can edit the text in the entry, balance
already is created and does not update constantly. So the text in balance
doesn’t update.
EDIT:
Here's what you can do(Feel free to edit the names of variables, customize them and edit the function):
from tkinter import *
root = Tk()
#Defining the update label function
def updateLbl():
lbl.config(text=enter.get())
root.after(1000, updateLbl)
enter = Entry(root)
enter.pack()
enter.insert(0, "text")
lbl = Label(root)
lbl.pack()
#calling the function
updateLbl()
root.after(1000, updateLbl)
root.mainloop()