0

I asked a question yesterday explaining a basic calculator I was making. So far, I haven't been able to get text to display AT ALL in a text widget. This is what I'm using:

text = Tk()

ans_text = Text(text, width=40, height=10)
ans_text.pack

ans_text.insert("1.0", 0, 'test')

mainloop()

That's just something from effbot with modified variables. I haven't bothered to create any classes or define functions, except for the mathematical functions used in this "calculator." I don't exactly see the need to.

So how can I get text to display? I've just seen stuff about making a canvas and I don't really understand that. I just went some letters and numbers to show up :P

1 Answer 1

1

The text (a zero) is being inserted, but the widget isn't visible which is why you aren't seeing it. You are forgetting the () when trying to pack the widget. Change the pack statement to look like this:

ans_text.pack()

With that modification your code will insert a zero as the first character of the text widget and apply the tag text to that character.

Whenever something doesn't appear the way you expect, a really good first thing to try is to temporarily give the widget a distinctive color. It will then become obvious whether the widget isn't working the way you want (eg: text isn't being inserted), or it's working the way you want but it's not visible on the screen.

Sign up to request clarification or add additional context in comments.

3 Comments

I forgot that. Thanks for correcting me! Aside from that, and back to the main "question" in my question, how can I get variables, specifically integers and floating points to display. Since it's a calculator I can't just type them in I need the variables to display.
I don't understand the question. Are you aware you can use variables when you call ans_text.insert?
Yeah, right after I commented I figured that out. Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.