Tkinter, Python: How do I save text entered in the Entry widget? How do I move a label?
Posted
by
user3692825
on Stack Overflow
See other posts from Stack Overflow
or by user3692825
Published on 2014-05-30T21:00:36Z
Indexed on
2014/05/30
21:26 UTC
Read the original article
Hit count: 178
I am a newbie at programming and my program is not stellar but hopefully it's ok because I have only been using it for a couple days now.
I am having trouble in my class "Recipie". In this class I am having trouble saving the text in my Entry widget. I know to use the .get() option but when I try to print it, it doesn't (whether it is within that defined method or not). So that is my main concern. I want it to save the text entered as a string when I press the button: b.
My other minor question is, how can I move the label. When I have tried I have used the height and width options, but that just expands the label. I want to move the text to create a title above my Entry boxes. Is label the right widget to use or would it be easier to use a message box widget? So it would look like, for example (but like 8 pixels down and 20 to the right):
ingredients
textbox
button labeled as: add an ingredient
And I am not sure the option .pack(side="...") or .place(anchor="...") are the right options to use for my buttons or entry boxes or labels.
Any help is greatly appreciated!!! And if you could add comments to your code explaining what you did, that would be so helpful. Thank you!!!
import Tkinter
class Recipie(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.title("New Recipie")
self.geometry("500x500")
def name(self):
name = Tkinter.Label(self, text="Title:", width=39)
name.place(anchor="nw")
insert_name = Tkinter.Entry(self)
insert_name.pack()
insert_name.focus_set()
def ingredients(self):
e = Tkinter.Entry(self)
e.pack()
e.focus_set()
def addingredient(self):
but = Tkinter.Button(self, text="Add Ingredients", width=15, command=self.ingredients)
but.pack(side="bottom")
def procedure(self):
txt = Tkinter.Label(self, text="List the Steps:")
txt.place(anchor="n")
p = Tkinter.Entry(self)
p.place(anchor="nw")
p.focus_set()
def savebutton(self):
print insert_name.get()
print e.get()
print p.get()
b = Tkinter.Button(self, text="Save Recipie", width=15, command=savebutton)
top = Recipie()
top.mainloop()
© Stack Overflow or respective owner