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

  • SEARCH
  • Home
  • 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 7731547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:30:24+00:00 2026-06-01T06:30:24+00:00

I have been following the validation for Entry boxes from here . The code

  • 0

I have been following the validation for Entry boxes from here. The code below is from the answer with the added condition that if the entered value is 'Q' then the program adds 'test' to the beginning of the Entry value.

However once this value is inserted, all validation appears to go out of the window and the Entry allows upper-case values. Some testing on my program shows the validation command (OnValidate in this case) isn’t being called upon any further events of the Entry (key, focusin/out etc).

import Tkinter as tk
class MyApp():
    def __init__(self):
        self.root = tk.Tk()
        vcmd = (self.root.register(self.OnValidate), 
                '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W')
        self.entry = tk.Entry(self.root, validate="key", 
                              validatecommand=vcmd)
        self.entry.pack()
        self.root.mainloop()

    def OnValidate(self, d, i, P, s, S, v, V, W):
        if S == "Q":
            self.entry.insert(0,"test")
        # only allow if the string is lowercase
        return (S.lower() == S)

app=MyApp()

The reason for me doing this is I want the Entry to display a default value if its value is left empty after any changes that are made by a user. (i.e. my condition would be if not P on focusout)

Any ideas how to implement this or what’s going wrong in the above much appreciated.

  • 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-06-01T06:30:26+00:00Added an answer on June 1, 2026 at 6:30 am

    I’m going to answer completely based on:

    I want the Entry to display a default
    value if its value is left empty after any changes that are made by a
    user.

    and hope that this example points you to what you want:

    import tkinter
    
    def analyze(event=None):
        content = entry_contents.get()
        if content == "":
            entry_contents.set("default")
    
    root = tkinter.Tk()
    
    entry_contents = tkinter.StringVar()
    entry = tkinter.Entry(root, textvariable=entry_contents)
    entry.grid()
    
    text = tkinter.Text(root, font=("Georgia", "12"))
    text.grid()
    
    entry.bind("<FocusOut>", analyze)
    
    root.mainloop()
    

    or if a control variable wont be of any use to you:

    import tkinter
    
    def analyze(event=None):
        content = entry.get()
        if content == "":
            entry.insert(0, "default")
    
    root = tkinter.Tk()
    
    entry = tkinter.Entry(root)
    entry.grid()
    
    text = tkinter.Text(root, font=("Arial", "12", "bold"))
    text.grid()
    
    entry.bind("<FocusOut>", analyze)
    
    root.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been following the affableBean tutorial from the NetBeans site located here .
I have been following some MVC tutorials that connect to a sql mdf database
I have the following code that works fine on my localhost using IIS7 but
I have been trying to make a VBA code to do the following. I
I have been following the usage of JavaScript for the past few years, and
I have been following the following post on using multiple ItemTemplates in a ListView
I have been following mozilla developer network's docs and created a transition for my
I have been following a couple of articles regarding RESTful web services with WCF
I have been following a tutorial on how to write a basic tile map
I have been following the tutorial on Microsofts website and they use GameTime to

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.