How can I make a button print in the display I created? (Tkinter)

drewbula99

I have been working on an app in python for a teacher at my school. What I want it to do is have a simple GUI and a way I can type in a word and it will print the words value in the same slot i typed the word.(kind of like a calculator) A=1 B=2 C=3 etc. It is fairly simple, as i am a beginner, but I can't quite get my button to show the value of the words I type in. If anyone could help it would be great! Thanks! Here is my code so far:

from Tkinter import *
import sys

def dollaramount():
    print sum(map(" abcdefghijklmnopqrstuvwxyz".index, raw_input().lower()))


root = Tk()
frame = Frame(root)
frame.pack()
num1=StringVar()

topframe = Frame(root)
topframe.pack(side=TOP)

txtDisplay=Entry(frame, textvariable = num1, bd= 20, insertwidth= 1, font= 30, bg="white", fg="black")
txtDisplay.pack(side=TOP)

button1 = Button(topframe, padx=16, pady=16, bd=8, text="=", bg="white", fg="black", command=dollaramount)
button1.pack(side=LEFT)

root.mainloop()
j_4321

I guess what you want is the following:

from Tkinter import *
import sys

def dollaramount():
    # get the word written in the entry
    word = num1.get()
    # compute its value
    val = sum(map(" abcdefghijklmnopqrstuvwxyz".index, word.lower()))
    # display its value in the entry
    num1.set("%s=%i" % (word, val))

root = Tk()
frame = Frame(root)
frame.pack()
num1=StringVar(root)

topframe = Frame(root)
topframe.pack(side=TOP)

txtDisplay=Entry(frame, textvariable = num1, bd= 20, insertwidth= 1, font= 30, bg="white", fg="black")
txtDisplay.pack(side=TOP)

button1 = Button(topframe, padx=16, pady=16, bd=8, text="=", bg="white", fg="black", command=dollaramount)
button1.pack(side=LEFT)

root.mainloop()

Your dollaramount function was not working because you used command line specific functions print and raw_input instead of using the set and get methods of the StringVar. I commented the code so that you can understand what it does.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I display the data created?

From Dev

How can I display legend in Tkinter?

From Dev

How can I display email messages in Tkinter?

From Dev

Tkinter - How can I make a button can create new window and close the main window

From Dev

How can I display the data I created in a linked list?

From Dev

How can I make inputs display inline?

From Dev

How I can make a button for browse a folder?

From Dev

How can I make a unlink button in PHP

From Dev

How can I make the button more visible?

From Dev

How can I make a button tag to expand?

From Dev

How can I make a functioning animated button?

From Dev

How can I make a button that that triggers a script?

From Dev

How can i make a delete Button?

From Dev

How Can I Make a Fluid Button

From Dev

How can I make a Read More Button?

From Dev

How can I make a clickable button in OpenTK?

From Dev

Python tkinter: How can I ensure only ONE child window is created onclick and not a new window every time the button is clicked?

From Dev

Python tkinter: How can I ensure only ONE child window is created onclick and not a new window every time the button is clicked?

From Dev

How can I make my button display correctly on all media devices?

From Dev

How do I make this button quit the parent window in tkinter?

From Dev

How can I take an entry from tkinter and print it in a txt document?

From Dev

How can I set an OpenGL display (Window created by OpenGL) to maximized?

From Dev

How can I save button which was dynamically created

From Dev

How can I move shape created by a button on the canvas in WPF?

From Dev

How can I manage onClickListener of a dynamically created button?

From Dev

How can I access a button name if it was created in a for loop in python?

From Dev

How can I move shape created by a button on the canvas in WPF?

From Dev

How can i make data submitted by user to be into a new Firebase key, key only created when Submit button is clicked to pass the data

From Dev

How can I display text AND variables in a tkinter text widget

Related Related

  1. 1

    How can I display the data created?

  2. 2

    How can I display legend in Tkinter?

  3. 3

    How can I display email messages in Tkinter?

  4. 4

    Tkinter - How can I make a button can create new window and close the main window

  5. 5

    How can I display the data I created in a linked list?

  6. 6

    How can I make inputs display inline?

  7. 7

    How I can make a button for browse a folder?

  8. 8

    How can I make a unlink button in PHP

  9. 9

    How can I make the button more visible?

  10. 10

    How can I make a button tag to expand?

  11. 11

    How can I make a functioning animated button?

  12. 12

    How can I make a button that that triggers a script?

  13. 13

    How can i make a delete Button?

  14. 14

    How Can I Make a Fluid Button

  15. 15

    How can I make a Read More Button?

  16. 16

    How can I make a clickable button in OpenTK?

  17. 17

    Python tkinter: How can I ensure only ONE child window is created onclick and not a new window every time the button is clicked?

  18. 18

    Python tkinter: How can I ensure only ONE child window is created onclick and not a new window every time the button is clicked?

  19. 19

    How can I make my button display correctly on all media devices?

  20. 20

    How do I make this button quit the parent window in tkinter?

  21. 21

    How can I take an entry from tkinter and print it in a txt document?

  22. 22

    How can I set an OpenGL display (Window created by OpenGL) to maximized?

  23. 23

    How can I save button which was dynamically created

  24. 24

    How can I move shape created by a button on the canvas in WPF?

  25. 25

    How can I manage onClickListener of a dynamically created button?

  26. 26

    How can I access a button name if it was created in a for loop in python?

  27. 27

    How can I move shape created by a button on the canvas in WPF?

  28. 28

    How can i make data submitted by user to be into a new Firebase key, key only created when Submit button is clicked to pass the data

  29. 29

    How can I display text AND variables in a tkinter text widget

HotTag

Archive