Reputation: 491
Using python3. I'm new to tkinter writing a program with a GUI that takes some input parameters and does some data processing, so it needs entry boxes where I can type numbers in.
I cannot for the life of me figure out how to get the entry boxes to stop lagging, i.e: when a box is clicked on and typed into, the changes made to the text in that entry box don't appear until I click on another button or text box in the window. Functionally, the program still works like this but it's irritating not being able to see what I'm typing and others will eventually use this software.
I've gotten halfway to fixing the problem by putting in event bindings so that key presses trigger an update of the idle tasks. The text now updates while typing, but it's "one letter slow" (a typed letter appears only after the next letter is typed) and this is still not ideal.
Help?
MWE:
from tkinter import *
###Window: 'top'
top = Tk() #make window
top.geometry("670x360") #window size
top.wm_title("Test program for TKinter")#window title
#window and label background colour
bgcol='light sea green'
top.configure(background=bgcol) #set colour
#events to refresh window
def keypress(event):
print('key pressed')
#update all idle widgets (remove text box lag)
top.update_idletasks()
def mouseentry(event):
print('mouse entered text box')
#update all idle widgets (remove text box lag)
top.update_idletasks()
##text entry box
Label(top,background=bgcol, text="").pack() #spacing label
v = StringVar()
e=Entry(top, width=50, textvariable=v)#,height=1)
e.pack()
Label(top,background=bgcol, text="").pack() #spacing label
v.set("a default value")
s = e.get()
e.bind("<Key>",keypress)
e.bind("<Enter>",mouseentry)
#Label displaying text box contents (not working right now, not important)
Label(top,background=bgcol, textvariable=s).pack() #text display label
#make buttons appear on start
top.update()
top.mainloop()
How do I update the entry widget as it is typed? Is there something really simple that I'm overlooking?
Upvotes: 2
Views: 1866
Reputation: 491
Answer to own question:
Mainloop wasn't running in the background (or something) of my python install, for whatever reason, whether run via Anaconda or via the terminal.
Simple reinstall of Anaconda IDE with python3.4 fixed all my issues.
Upvotes: 0