TheoretiCAL
TheoretiCAL

Reputation: 20571

AutoCapitalize Tkinter Entry text input

Is there a relatively easy way to automatically capitalize a Tkinter Entry's text input in realtime? So as a user is inputting values, they automatically get capitalized. Thanks!

Upvotes: 1

Views: 3026

Answers (2)

user1459519
user1459519

Reputation: 720

You can bind to an event instead of using .trace() (in python 3.x, not tested in 2.x).

For details see my answer to this similar question: python - Converting entry() values to upper case

Upvotes: 1

A. Rodas
A. Rodas

Reputation: 20679

Yes, it can be easily accomplished with trace and str.capitalize:

from Tkinter import *

root = Tk()
var = StringVar()
entry = Entry(root, textvariable=var)
entry.pack(padx=20, pady=20)

def autocapitalize(*arg):
    var.set(var.get().capitalize())

var.trace("w", autocapitalize)
root.mainloop()

Upvotes: 2

Related Questions