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 8568935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:13:06+00:00 2026-06-11T18:13:06+00:00

My program should check if the first three letters of the input word are

  • 0

My program should check if the first three letters of the input word are similar to a predefined word.
I’ve made a GUI with Tkinter and want to get the letters of the input field.
Somehow I can’t implement it in like I would do without Tkinter.

That’s how I do it just for the shell:

text = raw_input('Enter a word: ')

if (text[0] + text[1] + text[2] == 'sag'):
    print "sagen"
else:
    print "error"

So, when I input the word “sagst” it checks the first three letters and should put out “sagen”. Works fine.

I learned that e.g. inputfield.get() gets the input of the entry “inputfield”.
But how can I check the first letters of that “inputfield”?
A small selection:

from Tkinter import*
root = Tk()

def check():
    if (text[0] + text[1] + text[2] == 'sag'):
        print "True"
    else:
        print "False"

inputfield = Entry(root)
inputfield.pack()

but = Button(root,text='Check!', command = check)
but.pack()

text = inputfield.get()

root.mainloop()

Does not work…

I hope you can understand my question and will answer soon. (Sorry for my bad english and my bad Python skills) 😉
Thanks!

  • 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-11T18:13:08+00:00Added an answer on June 11, 2026 at 6:13 pm

    Your check function will have to retrieve the textfield after the button has been pressed:

    def check():
        text = inputfield.get()
        print text.startswith('sag')
    

    I’ve changed your test a little, using .startswith(), and directly printing the result of that test (print will turn boolean True or False into the matching string).

    What happens in your code is that you define inputfield, retrieve it’s contents (obviously empty), and only then show the TKInter GUI window by running the mainloop. The user never gets a chance to enter any text that way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got a simple Javascript program here to accept and check a password. It should:
The assignment at my first year uni computing course says my program should read
Im writing a program that should read input via stdin, so I have the
I want the program to check how many large boxes are needed, then use
I am making a python program, and I want to check if it is
my program should print a message on the screen if the formula that the
This program should calculate the value of 2^1+2^2 + ... + 2^10: #include <stdio.h>
What the program should do: After the user clicks the delete button with a
The following line in my C program should provided All/Group/Owner read and write permissions
If a user types in [[0,0,0], [0,0,1], [1,1,0]] and press enter, the program should

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.