473,395 Members | 1,641 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,395 software developers and data experts.

How to validate entry is alphanumeric,Tkinter

I have an entry that i would like to make sure that it is only alphanumeric. how can i do so?
Expand|Select|Wrap|Line Numbers
  1. def validate_code(var):
  2.     new_value = var.get()
  3.     try:
  4.         new_value == '' or int(new_value)
  5.         validate_code.old_value = new_value
  6.     except:
  7.         var.set(validate_code.old_value)
  8.  
This is what I have so far. I already check if it is an int, now how to check if it is alphabet.
Thanks
Sep 28 '14 #1
1 2988
dwblas
626 Expert 512MB
import string and test for new_value in string.letters
Try this simple test of your current logic
Expand|Select|Wrap|Line Numbers
  1. def validate_code(new_value):
  2.      ##new_value = var.get()
  3.      try:
  4.          new_value == '' or int(new_value)
  5.          validate_code.old_value = new_value
  6.      except:
  7.          print "error", validate_code.old_value
  8.  
  9. validate_code("@")
  10. validate_code(" ") 
Sep 28 '14 #2

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

Similar topics

3
by: Phil Schmidt | last post by:
I'm trying to make a custom entry widget, as in the code that follows. There are two problems I'm trying to fix: 1) I would like the widget to behave as myEntry.Escape() does now, except that it...
5
by: Otto Krüse | last post by:
Hi everyone, I'm building a GUI in which I want, amongst other things, for people to fill in there postal code. The postal codes of my country (Holland) are in this format: 1234 AB So for the...
8
by: Derek Fountain | last post by:
I'm coming to Tkinter from Tcl/Tk. In Tcl I can get a variable in an event using the %<X> substitution mechanism. For example, I can set up a command like: entry .e -validate 1 -vcmd "checkkey...
7
by: Michael Onfrek | last post by:
Hi! I'm playing with entry again and trying to restrict length of entry widget to certain number of character, so users cannot enter more character into it. Any ideas? Reg. Michael Onfrek
2
by: wanwan | last post by:
let's say I already have some content. How do I set the widget so user cannot change it/?
2
by: Martyn Quick | last post by:
If I create a Tkinter.Entry widget, I can adjust the background and the text colours, using the background and foreground options. However, if the state is "disabled", then this has no effect and...
0
by: Dustan | last post by:
Earlier I asked about limitting what a user can enter in an Entry. I got a few greatly appreciated replies, but I was hoping it would be possible to take a more direct approach, that is, is there a...
4
by: Dustan | last post by:
Back in this post, I attempted to make a label look like a button:...
7
by: krishnakant Mane | last post by:
hello all, I seam to have noticed this a bit late but it appears to me that tkinter is being used very widely for gui development on all platform? is that right? since fredric lundh has written a...
3
by: ElBeardo | last post by:
Hello, I´m new to Python.. so this is a newbee question. I´d like to put the value enterd in the entryfield in a variable. I´m trying to build a calculator with python and TKinter, coding it in...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.