Re: [Tutor] blocking user access

2005-03-24 Thread Kent Johnson
Diana Hawksworth wrote:
Liam, I am using IDLE - and Tkinter, John and Liam. I have been working
through the book "Python Programming" by Michael Dawson.  One of his
programs calls for the entry of a password, then reveals a message.  What I
would like to do is make the Text widget that reveals the message, unusable
by a user!
I tried the state = DISABLED in the 2nd line of code below, where the widget
to display the text is created - and it did disable the Text widget - to the
extent that it wouldn't reveal the message!  I have tried multiple other
places to put the DISABLED - at the end of this code for instance, but it
doesn't seem to work there! Where can I place it so that it will prevent a
user access to that Text widget?
Also - assuming I can get it to work - what is the term I need to use to
enable to Text widget again so that it will continue to work the next time
around. I tried ENABLED - but was told that global name is not defined!
Here is a snippet from Fredrik Lundh's "An Introduction to Tkinter" that shows how to enable the 
widget, insert some text, then disable it again:
text.config(state=NORMAL)
text.delete(1.0, END)
text.insert(END, text)
text.config(state=DISABLED)

from http://www.pythonware.com/library/tkinter/introduction/x8309-patterns.htm
Kent
Any ideas? Thanks in advance for suggestions.
Diana
Here is the code:
# create text widget to display message
self.secret_txt = Text(self, width = 35, height = 5, wrap = WORD)
self.secret_txt.grid(row = 3, column = 0, columnspan = 2, sticky =
W)
def reveal(self):
""" Display message based on password. """
contents = self.pw_ent.get()
if contents == "secret":
message = "Here's the secret to living to 100: live to 99 " \
  "and then be VERY careful."
else:
message = "That's not the correct password, so I can't share " \
  "the secret with you."
self.secret_txt.delete(0.0, END)
self.secret_txt.insert(0.0, message)


Hi Diana,
Welcome.
Are you using IDLE? Could you provide a copy of your code?
Regards,
Liam Clarke
Still a newbie, but not as much. :)
On Wed, 23 Mar 2005 20:59:02 +1100, Diana Hawksworth
<[EMAIL PROTECTED]> wrote:
Hi!  I need help on blocking user access to a message box - for example,
the
program could provide an answer to an input.  At the moment, the user
has
access to - and can type into - that "answer" space. How do I prevent
that
from happening please?
Diana - a very newbie!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


--
'There is only one basic human right, and that is to do as you damn well
please.
And with it comes the only basic human duty, to take the consequences.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blocking user access

2005-03-24 Thread Diana Hawksworth
Liam, I am using IDLE - and Tkinter, John and Liam. I have been working
through the book "Python Programming" by Michael Dawson.  One of his
programs calls for the entry of a password, then reveals a message.  What I
would like to do is make the Text widget that reveals the message, unusable
by a user!

I tried the state = DISABLED in the 2nd line of code below, where the widget
to display the text is created - and it did disable the Text widget - to the
extent that it wouldn't reveal the message!  I have tried multiple other
places to put the DISABLED - at the end of this code for instance, but it
doesn't seem to work there! Where can I place it so that it will prevent a
user access to that Text widget?

Also - assuming I can get it to work - what is the term I need to use to
enable to Text widget again so that it will continue to work the next time
around. I tried ENABLED - but was told that global name is not defined!

Any ideas? Thanks in advance for suggestions.

Diana

Here is the code:

# create text widget to display message
self.secret_txt = Text(self, width = 35, height = 5, wrap = WORD)
self.secret_txt.grid(row = 3, column = 0, columnspan = 2, sticky =
W)

def reveal(self):
""" Display message based on password. """
contents = self.pw_ent.get()
if contents == "secret":
message = "Here's the secret to living to 100: live to 99 " \
  "and then be VERY careful."

else:
message = "That's not the correct password, so I can't share " \
  "the secret with you."

self.secret_txt.delete(0.0, END)
self.secret_txt.insert(0.0, message)




> Hi Diana,
>
> Welcome.
>
> Are you using IDLE? Could you provide a copy of your code?
>
>
> Regards,
>
> Liam Clarke
>
> Still a newbie, but not as much. :)
>
>
> On Wed, 23 Mar 2005 20:59:02 +1100, Diana Hawksworth
> <[EMAIL PROTECTED]> wrote:
> >
> > Hi!  I need help on blocking user access to a message box - for example,
the
> > program could provide an answer to an input.  At the moment, the user
has
> > access to - and can type into - that "answer" space. How do I prevent
that
> > from happening please?
> >
> > Diana - a very newbie!
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
> >
>
>
> -- 
> 'There is only one basic human right, and that is to do as you damn well
please.
> And with it comes the only basic human duty, to take the consequences.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blocking user access

2005-03-23 Thread John Fouhy
Diana Hawksworth wrote:
Hi!  I need help on blocking user access to a message box - for example, 
the program could provide an answer to an input.  At the moment, the 
user has access to - and can type into - that "answer" space. How do I 
prevent that from happening please?
Are you using Tkinter?
You could bind '' to nothing in the entry widget.  eg:
self.answer = Tkinter.Entry(master)
def noop(e):
return 'break'
self.answer.bind('', noop)
--- actually, scratch that.  For Tkinter, just make the widget disabled.
self.answer.config(state=Tkinter.DISABLED)
Just remember that it needs to be enabled when you put the answer in.
--
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blocking user access

2005-03-23 Thread Kent Johnson
Diana Hawksworth wrote:
Hi!  I need help on blocking user access to a message box - for example, 
the program could provide an answer to an input.  At the moment, the 
user has access to - and can type into - that "answer" space. How do I 
prevent that from happening please?
It sounds like you want to disable writing into a text field in your gui? Are you using Tkinter or 
another GUI toolkit?

In Tkinter you could use a Label widget, which is never editable, or you could use a Text widget 
with its 'state' option set to 'DISABLED' like this:
t=Text(state=DISABLED)

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blocking user access

2005-03-23 Thread Liam Clarke
Hi Diana,

Welcome. 

Are you using IDLE? Could you provide a copy of your code?


Regards, 

Liam Clarke

Still a newbie, but not as much. :)


On Wed, 23 Mar 2005 20:59:02 +1100, Diana Hawksworth
<[EMAIL PROTECTED]> wrote:
>  
> Hi!  I need help on blocking user access to a message box - for example, the
> program could provide an answer to an input.  At the moment, the user has
> access to - and can type into - that "answer" space. How do I prevent that
> from happening please? 
>   
> Diana - a very newbie! 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor