473,320 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Need help with the get() method of a Text entry

I have a simple little program that brings up asks the user to enter a
note, then is supposed to place that note into a text file when the
user hits the submit button. However, when the user hits the submit
button, absolutely nothing happens. IDLE doesn't give an error
message and the note is not entered into the text file. For
troubleshooting puposes, I wanted to see if IDLE would at least print
the user's input; it doesn't do that either. Can someone please help
me?

Here is the code:

from Tkinter import *

class Application(Frame):
""" GUI application that creates a story based on user input. """
def __init__(self, master):
""" Initialize Frame. """
Frame.__init__(self, master)
self.grid()
self.create_widgets()

def create_widgets(self):
""" Create widgets to get note information. """
# create instruction label and text entry for notes
Label(self,
text = "Notes"
).grid(row = 0, column = 0, columnspan = 2 )
self.notes_ent = Text(self, width = 75, height = 10, wrap =
WORD)
self.notes_ent.grid(row = 2, column = 0 ,columnspan = 7,
rowspan = 3, sticky = W)
create submit button
text1 = StringVar(self)
text1 = self.notes_ent.get(1.0, END)
self.notes_ent.config(state=NORMAL)
Button(self,
text = "Add Note",
command = self.add_note(text1)
).grid(row = 1, column = 0, sticky = W)


def add_note(self, text1):
print text1
text_file = open("write_it.txt", "a+")
text_file.write(text1)


root = Tk()
root.title("Mad Lib")
app = Application(root)
root.mainloop()

Apr 12 '07 #1
6 1422
Chad wrote:
I have a simple little program that brings up asks the user to enter a
note, then is supposed to place that note into a text file when the
user hits the submit button. However, when the user hits the submit
button, absolutely nothing happens. IDLE doesn't give an error
message and the note is not entered into the text file. For
troubleshooting puposes, I wanted to see if IDLE would at least print
the user's input; it doesn't do that either. Can someone please help
me?

Here is the code:

from Tkinter import *

class Application(Frame):
""" GUI application that creates a story based on user input. """
def __init__(self, master):
""" Initialize Frame. """
Frame.__init__(self, master)
self.grid()
self.create_widgets()

def create_widgets(self):
""" Create widgets to get note information. """
# create instruction label and text entry for notes
Label(self,
text = "Notes"
).grid(row = 0, column = 0, columnspan = 2 )
self.notes_ent = Text(self, width = 75, height = 10, wrap =
WORD)
self.notes_ent.grid(row = 2, column = 0 ,columnspan = 7,
rowspan = 3, sticky = W)
create submit button
text1 = StringVar(self)
text1 = self.notes_ent.get(1.0, END)
self.notes_ent.config(state=NORMAL)
Button(self,
text = "Add Note",
command = self.add_note(text1)
).grid(row = 1, column = 0, sticky = W)

def add_note(self, text1):
print text1
text_file = open("write_it.txt", "a+")
text_file.write(text1)

root = Tk()
root.title("Mad Lib")
app = Application(root)
root.mainloop()
Your main problem is that you are calling add_note when you bind it. You
don't want to do that. It will get called when the event (button press)
happens. Most (or hopefully) all of the remedy is:

1. rename text1 to self.text1
2. change "command = self.add_note(text1)" to
"command = self.add_note"
3. change "def add_note(self, text1):" to
"def add_note(self):"
4. delete "print text1"
5. chane "text_file.write(text1)" to
"text_file.write(text1.get())"

I think I got everything.

James
Apr 12 '07 #2
Chad wrote:
I have a simple little program that brings up asks the user to enter a
note, then is supposed to place that note into a text file when the
user hits the submit button. However, when the user hits the submit
button, absolutely nothing happens. IDLE doesn't give an error
message and the note is not entered into the text file. For
troubleshooting puposes, I wanted to see if IDLE would at least print
the user's input; it doesn't do that either. Can someone please help
me?

Here is the code:

from Tkinter import *

class Application(Frame):
""" GUI application that creates a story based on user input. """
def __init__(self, master):
""" Initialize Frame. """
Frame.__init__(self, master)
self.grid()
self.create_widgets()

def create_widgets(self):
""" Create widgets to get note information. """
# create instruction label and text entry for notes
Label(self,
text = "Notes"
).grid(row = 0, column = 0, columnspan = 2 )
self.notes_ent = Text(self, width = 75, height = 10, wrap =
WORD)
self.notes_ent.grid(row = 2, column = 0 ,columnspan = 7,
rowspan = 3, sticky = W)
create submit button
text1 = StringVar(self)
text1 = self.notes_ent.get(1.0, END)
self.notes_ent.config(state=NORMAL)
Button(self,
text = "Add Note",
command = self.add_note(text1)
).grid(row = 1, column = 0, sticky = W)


def add_note(self, text1):
print text1
text_file = open("write_it.txt", "a+")
text_file.write(text1)


root = Tk()
root.title("Mad Lib")
app = Application(root)
root.mainloop()
On second look, it seems you have deeper problems, some of which are:
text1 = StringVar(self)
text1 = self.notes_ent.get(1.0, END)
You obviously added the second because the first will never work. Get
rid of both lines. Even if you intended the second, it immediately
nullifies the first. Instead of my previous suggestions, do this:

1. delete both "text1 =" lines
2. change "command = self.add_note(text1)" to
"command = self.add_note"
3. change "def add_note(self, text1):" to
"def add_note(self):"
4. delete "print text1"
5. change "text_file.write(text1)" to
"text_file.notes_ent.get(1.0, END)

James

Apr 12 '07 #3
James Stroud wrote:
Chad wrote:
>I have a simple little program that brings up asks the user to enter a
note, then is supposed to place that note into a text file when the
user hits the submit button. However, when the user hits the submit
button, absolutely nothing happens. IDLE doesn't give an error
message and the note is not entered into the text file. For
troubleshooting puposes, I wanted to see if IDLE would at least print
the user's input; it doesn't do that either. Can someone please help
me?

Here is the code:

from Tkinter import *

class Application(Frame):
""" GUI application that creates a story based on user input. """
def __init__(self, master):
""" Initialize Frame. """
Frame.__init__(self, master)
self.grid()
self.create_widgets()

def create_widgets(self):
""" Create widgets to get note information. """
# create instruction label and text entry for notes
Label(self,
text = "Notes"
).grid(row = 0, column = 0, columnspan = 2 )
self.notes_ent = Text(self, width = 75, height = 10, wrap =
WORD)
self.notes_ent.grid(row = 2, column = 0 ,columnspan = 7,
rowspan = 3, sticky = W)
create submit button
text1 = StringVar(self)
text1 = self.notes_ent.get(1.0, END)
self.notes_ent.config(state=NORMAL)
Button(self,
text = "Add Note",
command = self.add_note(text1)
).grid(row = 1, column = 0, sticky = W)


def add_note(self, text1):
print text1
text_file = open("write_it.txt", "a+")
text_file.write(text1)


root = Tk()
root.title("Mad Lib")
app = Application(root)
root.mainloop()

On second look, it seems you have deeper problems, some of which are:
text1 = StringVar(self)
text1 = self.notes_ent.get(1.0, END)

You obviously added the second because the first will never work. Get
rid of both lines. Even if you intended the second, it immediately
nullifies the first. Instead of my previous suggestions, do this:

1. delete both "text1 =" lines
2. change "command = self.add_note(text1)" to
"command = self.add_note"
3. change "def add_note(self, text1):" to
"def add_note(self):"
4. delete "print text1"
5. change "text_file.write(text1)" to
"text_file.notes_ent.get(1.0, END)

James
Or rather
5. change "text_file.write(text1)" to
"text_file.write(self.notes_ent.get(1.0, END))"
Apr 12 '07 #4
On Apr 12, 5:03 pm, James Stroud <jstr...@mbi.ucla.eduwrote:
James Stroud wrote:
Chad wrote:
I have a simple little program that brings up asks the user to enter a
note, then is supposed to place that note into a text file when the
user hits the submit button. However, when the user hits the submit
button, absolutely nothing happens. IDLE doesn't give an error
message and the note is not entered into the text file. For
troubleshooting puposes, I wanted to see if IDLE would at least print
the user's input; it doesn't do that either. Can someone please help
me?
Here is the code:
from Tkinter import *
class Application(Frame):
""" GUI application that creates a story based on user input. """
def __init__(self, master):
""" Initialize Frame. """
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
""" Create widgets to get note information. """
# create instruction label and text entry for notes
Label(self,
text = "Notes"
).grid(row = 0, column = 0, columnspan = 2 )
self.notes_ent = Text(self, width = 75, height = 10, wrap =
WORD)
self.notes_ent.grid(row = 2, column = 0 ,columnspan = 7,
rowspan = 3, sticky = W)
create submit button
text1 = StringVar(self)
text1 = self.notes_ent.get(1.0, END)
self.notes_ent.config(state=NORMAL)
Button(self,
text = "Add Note",
command = self.add_note(text1)
).grid(row = 1, column = 0, sticky = W)
def add_note(self, text1):
print text1
text_file = open("write_it.txt", "a+")
text_file.write(text1)
root = Tk()
root.title("Mad Lib")
app = Application(root)
root.mainloop()
On second look, it seems you have deeper problems, some of which are:
text1 = StringVar(self)
text1 = self.notes_ent.get(1.0, END)
You obviously added the second because the first will never work. Get
rid of both lines. Even if you intended the second, it immediately
nullifies the first. Instead of my previous suggestions, do this:
1. delete both "text1 =" lines
2. change "command = self.add_note(text1)" to
"command = self.add_note"
3. change "def add_note(self, text1):" to
"def add_note(self):"
4. delete "print text1"
5. change "text_file.write(text1)" to
"text_file.notes_ent.get(1.0, END)
James

Or rather
5. change "text_file.write(text1)" to
"text_file.write(self.notes_ent.get(1.0, END))"

Thank you, that worked very well.

Apr 12 '07 #5
Chad wrote:
On Apr 12, 5:03 pm, James Stroud <jstr...@mbi.ucla.eduwrote:
>James Stroud wrote:
>>Chad wrote:
I have a simple little program that brings up asks the user to enter a
note, then is supposed to place that note into a text file when the
user hits the submit button. However, when the user hits the submit
button, absolutely nothing happens. IDLE doesn't give an error
message and the note is not entered into the text file. For
troubleshooting puposes, I wanted to see if IDLE would at least print
the user's input; it doesn't do that either. Can someone please help
me?
[...]
[James second-guesses himself twice]
>
Thank you, that worked very well.
I thought it was particularly helpful of James to do the debugging for
you without waiting for you to point out the errors in his first and
second submissions. You just don't *get* help like that most places
nowadays.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com
Apr 13 '07 #6
Chad wrote:
On Apr 12, 5:03 pm, James Stroud <jstr...@mbi.ucla.eduwrote:
>James Stroud wrote:
>>Chad wrote:
I have a simple little program that brings up asks the user to enter a
note, then is supposed to place that note into a text file when the
user hits the submit button. However, when the user hits the submit
button, absolutely nothing happens. IDLE doesn't give an error
message and the note is not entered into the text file. For
troubleshooting puposes, I wanted to see if IDLE would at least print
the user's input; it doesn't do that either. Can someone please help
me?
[...]
[James second-guesses himself twice]
>
Thank you, that worked very well.
I thought it was particularly helpful of James to do the debugging for
you without waiting for you to point out the errors in his first and
second submissions. You just don't *get* help like that most places
nowadays.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Apr 13 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil Schmidt | last post by:
I'm trying to make a custom entry widget, as in the code that follows. There are two problems I'm trying to fix: 1) I would like the widget to behave as myEntry.Escape() does now, except that it...
8
by: TurboDuster | last post by:
I've posted a question here twice and unfortunatly got no reply. Maybe it's a hard question. Maybe I've broken some sort of netiquette and I'm being shunned. Don't know. If the former, I would...
6
by: MLH | last post by:
I would like a scanner - something like a pencil that would allow me to attempt to scan printed text off hardcopies. Not all text on a page, mind you. Something I could use to scan just the words...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
27
by: ted benedict | last post by:
hi everybody, i hope this is the right place to discuss this weird behaviour. i am getting dynamically generated text or xml from the server side using xmlhttprequest. if the server side data is...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
5
by: Alexnb | last post by:
I am not sure what is going on here. Here is the code that is being run: def getWords(self): self.n=0 for entry in self.listBuffer: self.wordList = entry.get() self.n=self.n+1 print...
4
by: hussain3047 | last post by:
Hi i am a beginner in C sharp and trying to develop a wince 5.0 device application using C sharp. i am using a thread in the Form1 Load method which is continously running a method named...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.