Reputation: 81
So when I first open the window, the everything else is fine, I can click the buttons and all but when I try to click the textbox and type something inside, the cursor does not appear and I can't type anything. However, if I switch to any other window(literally anything from chrome to notepad) and switch back, I'm able to normally type inside the textbox.
I'm not sure how to solve this. Could anyone help me? My Python version is 3.8.0.
Here's part of my code and 'top' is my tkinter window's variable name. inputtxt1 and inputtxt2 is the textboxes I am having a problem with.
load_txt.set("analyze")
a_bt = Button(top, text = "analyze", command = _analyze_)
a_bt.config(textvariable=load_txt)
a_bt.grid(row=4, column=0, sticky='E')
dir_bt = Button(top, text = "change dir", command = ch_dir)
dir_bt.grid(row=4, column=1, sticky='W')
save_button['command'] = save_change
save_button.grid(row=5, column=0, sticky='E')
top.geometry("600x1000")
top.resizable(width = True, height = True)
Label(top, text = "start_slab").grid(row=0, column=0, sticky='E')
inputtxt1 = Text(top, height = 1, width = 5, state='normal')
inputtxt1.grid(row=1, column=0, sticky='E')
Label(top, text = "end_slab").grid(row=2, column=0, sticky='E')
inputtxt2 = Text(top, height = 1, width = 5, state='normal')
inputtxt2.grid(row=3, column=0, sticky='E')
avg_bt = Button(top, text = "avg", command = show_avg)
prev_bt = Button(top, text = "prev", command = show_prev)
next_bt = Button(top, text = "next", command = show_next)
#panel.pack()
dir_name = askdirectory()
top.bind("<Return>", analyze)
top.grid_rowconfigure(0, weight=0)
top.mainloop()
Thank you!
===========Edit===========
Here is a short working version of the code
from tkinter.filedialog import askdirectory
from tkinter import Tk, Label, Button, Text
frame_idx = 0
dir_name = None
top = Tk()
save_button = Button(top, text = "save images")
a_bt = Button(top, text = "analyze")
a_bt.grid(row=4, column=0, sticky='E')
dir_bt = Button(top, text = "change dir")
dir_bt.grid(row=4, column=1, sticky='W')
save_button.grid(row=5, column=0, sticky='E')
top.geometry("600x1000")
top.resizable(width = True, height = True)
Label(top, text = "start_slab").grid(row=0, column=0, sticky='E')
inputtxt1 = Text(top, height = 1, width = 5, state='normal')
inputtxt1.grid(row=1, column=0, sticky='E')
Label(top, text = "end_slab").grid(row=2, column=0, sticky='E')
inputtxt2 = Text(top, height = 1, width = 5, state='normal')
inputtxt2.grid(row=3, column=0, sticky='E')
dir_name = askdirectory()
top.grid_rowconfigure(0, weight=0)
top.mainloop()
It seems that when I don't have the askdirectory function, this does not become a problem but if I do, the problem occurs.
Upvotes: 0
Views: 222
Reputation: 7710
Add top.update()
or top.update_idletasks()
just before dir_name = askdirectory()
. I think that the askdirectory
interferes with the entries so they stop handling events until they are redrawn on the screen (when you refocus the window). That might be a tcl bug? I have no idea how tcl handles events when askdirectory
is called.
Upvotes: 1