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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:08:23+00:00 2026-06-11T16:08:23+00:00

I’m switching over a small app (Python 2.7.3/32 on Win 7/64) to use ttk

  • 0

I’m switching over a small app (Python 2.7.3/32 on Win 7/64) to use ttk and I’m having trouble making ttk.Entry work the way tk.Entry does; ttk.Entry isn’t updating the displayed entry box when I set its contents:

import Tkinter as tk
import ttk

class SampleApp(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        part_num = '1234'
        newPNVar = tk.StringVar()
        newPN = ttk.Entry(self, width=13, textvariable=newPNVar)
        newPNVar.set(part_num)
        newPN.pack()
        #newPN.insert(0, part_num)  also didn't work

        print newPNVar.get()


app = SampleApp()
app.mainloop()

If i replace ttk.Entry with tk.Entry and run the example, 1234 shows up in the Entry box, but not if it is a ttk.Entry. How do I get them to behave the same way?

  • 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-11T16:08:24+00:00Added an answer on June 11, 2026 at 4:08 pm

    It appears that ttk and tk hold on to the text variable a little differently. It appears that the root cause is that newPNVar is getting garbage collected since you aren’t holding on to a reference. This doesn’t seem to affect tk.Entry, but does affect ttk.Entry.

    The quick fix is to keep a reference to newPNVar (eg: self.newPNVar), which is probably a wise thing regardless of this difference in behavior.

    This works for me on Windows:

    import Tkinter as tk
    import ttk
    
    class SampleApp(tk.Tk):
        def __init__(self, *args, **kwargs):
            tk.Tk.__init__(self, *args, **kwargs)
    
            part_num = '1234'
            self.newPNVar = tk.StringVar()
            newPN = ttk.Entry(self, width=13, textvariable=self.newPNVar)
            self.newPNVar.set(part_num)
            newPN.pack()
            #newPN.insert(0, part_num)  also didn't work
    
            print self.newPNVar.get()
    
    
    app = SampleApp()
    app.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.