473,597 Members | 2,198 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to validate entry is alphanumeric,Tk inter

3 New Member
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 3013
dwblas
626 Recognized Expert Contributor
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
4921
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 happens on loss of focus, not when pressing Esc. 2) TABbing between multiple entry fields does undesired things with the selection, and with cursor placement. Can anyone offer any suggestions for how to fix this? I'm attemting to
5
10889
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 input I use two entry widgets, one of a length of (characters) for the numbers and one of lenght 2 for the letters. What I don't like is that although the visible part of the widgets thus are 4 and 2 characters, users can actually input more...
8
3042
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 %d" knowing that the '%d' will be replaced by something useful - whether the entry widget has recieved an insert or deletion in this case. The checkkey procedure will recieve "insert", "delete" or whatever as its first parameter.
7
18295
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
1649
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
14068
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 it just appears as grey on a light grey background. E.g., Tkinter.Entry(root, foreground="black", background="white", state="disabled").grid() does not do what I expected. What is the correct way to adjust the foreground and background on...
0
1241
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 method I can override, when creating a class that inherits the Entry methods, that is called whenever the user enters a key? I'm thinking something like this in the override version: def method(self, key): if key in "1234567890":...
4
1896
by: Dustan | last post by:
Back in this post, I attempted to make a label look like a button: http://groups.google.com/group/comp.lang.python/browse_thread/thread/a83195d3970a6851/2053cbaec1bc1f19?auth=DQAAAHkAAAAMDAWnhNnzpuKlwOKZUwAGUTtT2Ay-EAB7rCY6SnwfnDzZ98M37bZDW2Is0LrBVrr8XEgPfcuOkiUE-CrSsKbBSX-67voDUXfbATBd0eYNMClezby4EXT2fuLm6f0llJ_xMO8BfkjVho_7CZvlf_9tNGnJixTbq8zr21ODZBhouQ Alright, I've learned my lesson - don't use a new widget; modify the old one. ...
7
1941
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 very good introduction to tkinter (was that just an intro?), I have got keen interest to know the following. may be fredric himself might put some light on these points. 1. I seriously don't intend to start a flame war but does tkinter stand...
3
30199
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 just python works good. But making it with TK is a bit hard. This is my unfinished code, i have tryed get() in many ways,.but I cant make it work. I´m only need to get knowledge about using get() now,.. I now there is other thing undone in this...
0
7962
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8267
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8024
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5844
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2394
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1229
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.