Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter Entry widget in Python is uneditable

When I run this code, the file picker comes up, and then when I finish with it, I can't type in the entry widget until I focus on another window and then come back. Why is this happening?

import tkinter as tk
from tkinter.filedialog import askopenfilename


location = ''
start = tk.Tk()

tk.Label(text='What is the name of your table?').pack()
box = tk.Entry(start, exportselection=0, state=tk.DISABLED)
box.pack()
button = tk.Button(start, text='OK', command=lambda e: None)
button.pack()
location = askopenfilename(defaultextension='.db', 
                           title="Choose your database", 
                           filetypes=[('Database Files', '.db'), ('All files', '*')])
box.config(state=tk.NORMAL)

start.mainloop()
like image 724
ddsnowboard Avatar asked Nov 10 '22 03:11

ddsnowboard


1 Answers

You just write box.focus_force() below box.pack() and that should do the work for you.

like image 119
saurav Avatar answered Nov 14 '22 23:11

saurav