473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do I make tkinter text entry to all uppercase?

Thekid
145 100+
I have a toplevel window in tkinter that has some entry fields. Is there a way that I can get it to change the letters typed in it to uppercase, either as they're typed or after they're typed, while in the entry field? I don't want whatever is typed in to print out to IDLE. So as an example:

Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. win = Tk()
  3.  
  4. Label(win, text='Enter user nick:').pack(side=LEFT)
  5. Entry(win, width=20).pack(side=LEFT)
  6.  
  7. mainloop()
  8.  
As, or after I type Thekid in the entry box, I'd like it to turn to all caps.
Oct 8 '10 #1

✓ answered by bvdet

You can bind an event to your widget that calls a function to convert the text to upper case. You will need to initialize a textvariable for the Entry widget. In your case, there is nothing else to take the focus, otherwise you could bind "<FocusOut>" to the widget. "<KeyRelease>" works nicely however.
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. win = Tk()
  3.  
  4. def caps(event):
  5.     v.set(v.get().upper())
  6.  
  7. Label(win, text='Enter user nick:').pack(side=LEFT)
  8. v = StringVar()
  9. w = Entry(win, width=20, textvariable=v)
  10. w.pack(side=LEFT)
  11. w.bind("<KeyRelease>", caps)
  12.  
  13. mainloop()

2 15866
bvdet
2,851 Expert Mod 2GB
You can bind an event to your widget that calls a function to convert the text to upper case. You will need to initialize a textvariable for the Entry widget. In your case, there is nothing else to take the focus, otherwise you could bind "<FocusOut>" to the widget. "<KeyRelease>" works nicely however.
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. win = Tk()
  3.  
  4. def caps(event):
  5.     v.set(v.get().upper())
  6.  
  7. Label(win, text='Enter user nick:').pack(side=LEFT)
  8. v = StringVar()
  9. w = Entry(win, width=20, textvariable=v)
  10. w.pack(side=LEFT)
  11. w.bind("<KeyRelease>", caps)
  12.  
  13. mainloop()
Oct 8 '10 #2
Thekid
145 100+
I see! That works like a charm! Thanks
Oct 8 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mauro Baraldi | last post by:
Hello World... Someone can help me with a Tkinter doubt. I need to get some data, from a Tkinter text objetc and write to a variable. And, sent to a text objetc some data from a var. Thanks...
2
by: Harry Pehkonen | last post by:
While setting up some unit tests, I came to the conclusion that a Tkinter Text widget can never be empty, but will always (?) contain a \n. Here is a brief example: >>> import Tkinter >>> t =...
0
by: Michael Spencer | last post by:
Using: Python 2.3.3 Tkinter.TclVersion = 8.4000000000000004 Windows XP Calling edit_modified() on a Tkinter.Text object raises TypeError when it gets a Boolean True response. Exception in...
8
by: James Stroud | last post by:
Hello All, I would like for a tkinter text widget to be aware of how big the frame that contains it is, then I would like for it to reset its width to the appropriate number of characters when...
2
by: William Gill | last post by:
The tkinter text widget uses indexes to identify row:column offsets within the text, but it seems counter intuitive to have to convert row and column integers to a string like "0.1'. It's great...
6
by: Gigs_ | last post by:
I'm writing text editor. How to enable/disable (cut, copy etc.) when text is selected/not selected
6
by: Chad | last post by:
I have a simple little program that brings up asks the user to enter a note, then is supposed to place that note into a text file when the user hits the submit button. However, when the user hits...
0
by: Alex Bryan | last post by:
Hey guys. I am having trouble understanding the get() method from the Tkinter Text() widget. It isn't like the entry.get() one I am used to. I know you have to put tags in, or at least I read. I...
0
by: John McMoangle | last post by:
Hey guys. I am having trouble understanding the get() method from The arguments to the get method of the Text widget are strings in the form of "line.position". So, text.get('1.5', '2.7')...
0
by: Alexnb | last post by:
I am writing a program in which there is a textbox and in it the program auto inputs a series of words, and definitions for each word. I want to make it formatted nicely to where the word is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.