Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4004422
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:16:18+00:00 2026-05-20T08:16:18+00:00

I want a text entry field (gtk.Entry) that accepts only hexadecimal characters as valid

  • 0

I want a text entry field (gtk.Entry) that accepts only hexadecimal characters as valid input from the user.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:16:18+00:00Added an answer on May 20, 2026 at 8:16 am

    Filtering may be done by connecting to the ‘insert_text’ signal and manipulating the entered text in the signal handler.
    Here is example code for validating Hex characters:

    #!/usr/bin/env python
    import gtk, pygtk, gobject, string
    
    class HexEntry(gtk.Entry):
        """A PyGTK text entry field which allows only Hex characters to be entered"""
    
        def __init__(self):
            gtk.Entry.__init__(self)
            self.connect("changed", self.entryChanged)
            self.connect("insert_text", self.entryInsert)
    
        def entryChanged(self, entry):
            # Called only if the entry text has really changed.
            print "Entry changed"
    
        def entryInsert(self, entry, text, length, position):
            # Called when the user inserts some text, by typing or pasting.
            print "Text inserted"
    
            position = entry.get_position() # Because the method parameter 'position' is useless
    
            # Build a new string with allowed characters only.
            result = ''.join([c for c in text if c in string.hexdigits])
    
            # The above line could also be written like so (more readable but less efficient):
            # result = ''
            # for c in text:
            #     if c in string.hexdigits:
            #         result += c
    
            if result != '':
                # Insert the new text at cursor (and block the handler to avoid recursion).
                entry.handler_block_by_func(self.entryInsert)
                entry.insert_text(result, position)
                entry.handler_unblock_by_func(self.entryInsert)
    
                # Set the new cursor position immediately after the inserted text.
                new_pos = position + len(result)
    
                # Can't modify the cursor position from within this handler,
                # so we add it to be done at the end of the main loop:
                gobject.idle_add(entry.set_position, new_pos)
    
            # We handled the signal so stop it from being processed further.
            entry.stop_emission("insert_text")
    
    def main():
        window = gtk.Window()
        window.connect("delete-event", gtk.main_quit)
        entry = HexEntry()
        window.add(entry)
        window.show_all()
        gtk.main()
    
    if __name__ == "__main__":
        main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to copy text files and only text files from src/ to dst/
I want to have a text box that the user can type in that
I'm trying to build a form field that can either accept a text entry,
I want to add text to speech user guided instruction to my applications. Where
I want to find any text in a file that matches a regexp of
I want to use SAPI Text-To-Speech engine from my ActionScript or Air application. is
Hey guys, I'm trying to add a textfield.text entry to an array. I want
I'm writing a text entry app that sits in the System Tray and assists
from Tkinter import * app = Tk() text_field = Entry(app) text_field.pack() app.mainloop() I want
I have this div: <div class=inauguration-image> I do not want this text to display,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.