Re: [Tutor] Print Output Location in Windows XP

2005-09-02 Thread geon
Tom Strickland napsal(a):

Up until now I have been running my Python programs in Linux. I just 
wrote one in Windows XP and I can't find the print output. The Python 
program has a print statement, and when I run the program a black window 
opens and I can see printing going on. However, when it's finished 
printing, the output window closes.

How do I get the output window to stay open, or where is the output stored?

  

You could:

* put raw_input() statement on the last line in your program
* run python with -i argument . i means stay interactive after run. 
example : python -i myfile.py

Hope this helps

-- 
geon


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


Re: [Tutor] Event handler for optionmenu

2005-08-15 Thread geon
Jorge Louis de Castro napsal(a):

Hi,

Thanks for your reply. It wasn't lazyness, believe me, I did look around for 
solutions and found something similar to yours here:

http://www.astro.washington.edu/owen/TkinterSummary.html#TracingVariables

The problem is that I have a class and it wants the callback function to be 
a global name (I also can't figure out hot to pass parameters to it)

By being a global name I can't access the var with widget.getvar(), and it 
complains if I use root by saying:

Exception in Tkinter callback
Traceback (most recent call last):
  File C:\Python24\Lib\lib-tk\Tkinter.py, line 1345, in __call__
return self.func(*args)
  File C:\Workplace\python\piim\Tkclient.py, line 312, in doLangChoices
varValue = root.getvar(name)
AttributeError: Tkclient instance has no attribute 'getvar'


  

Not sure what Tkclient() is... seems to be not child od Tk(), cause 
there is no getvar() function...
Anyway I am not able to run your script cause you used there both tabs 
and spaces for indentation. (see the row OPTIONS = 
[en,pt,es,it,fr,de], how much it is intended)

Shoudnt be there varValue = self.startw.getvar(name)? - just guessing - 
I can not check cause the indentation i scorrupted ;-)

geon


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


Re: [Tutor] How can I make this run right?

2005-08-15 Thread geon
Nathan Pinno napsal(a):

I put in a 4 and expected 24, and instead got 12. It is supposed to give 4! 
not 4*3.
---
  


Dear Nathan,

Everyone is giving you very good hints but seems to me you keep to 
resist :-)
Looks like you always wait for complete solution, dont you?
Here it is. There is one add and two changes. Can you see them?

n = int(raw_input(Number: ))
x = n-1
t=n
while 1:
   t = t*x
   if x  1:
   x -= 1
   else:
   break
print t

Its not the best solution for number!, but it is yours (and a bit of 
mine :-) )

-- 
geon


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


Re: [Tutor] help

2005-08-11 Thread geon




Dan Deternova napsal(a):
i am making a simple script to get the hang of Tkinter. i
want to use the input of the user from a Entry and calcuate the area. i
have tryied many way... as you can see in my script. the Entry is
under def area(): and the output i want is under def cal(): ...
please help me fix my code and explain to me what you did.. thanks in
advance.
  
  
  
here is corrected script, I just correct the area funciton and all what
belongs to it. Instead of DoubleVar, you could also use IntVar, if you
prefer

#program made and maintained by Dan Deternova
#start of program

from Tkinter import
*
# tells computer we are using Tkinter modual
from tkMessageBox import *
def cal():
 win4 = Toplevel
 print 'area = ', w.get()*h.get()
 
def notyet():
 showerror('not yet avalable')

win =
Tk()
# makes windows and has value for Tk
def makemenu(Tk):
 top = Menu(win)
 win.config(menu=top)

 file = Menu(top)
 file.add_command(label='save your name', command=newwin,
underline=0)
 file.add_command(label='quit', command=win.destroy, underline=0)
 file.add_command(label='quit all', command=win.quit, underline=0)
 top.add_cascade(label='file', menu=file, underline=0)
 edit = Menu(top, tearoff=0)
 edit.add_command(label='copy', command=notyet, underline=0)
 edit.add_command(label='paste', command=notyet, underline=0)
 edit.add_command(label='quit', command=win.destroy, underline=0)
 top.add_cascade(label='edit', menu=edit, underline=0)


def
newwin():
# callback to define button newwin.
 win2 =
Toplevel()
# makes new window when button is pressed. named win2
 widget = Label(win2, text='your name
here').pack() # line 'type your
name here' is printed on top of entry
 name = StringVar()
 widget = Entry(win2,
textvariable=name).pack() #
makes entry in new window at the top.
 widget = Label(win2, text='age
here').pack() # prints the
line 'age here'
 age = StringVar()
 widget = Entry(win2,
textvariable=age).pack() #
makes entry
 widget = Label(win2, text='type your address here').pack()
 address = StringVar()
 widget = Entry(win2, textvariable=address).pack()
 def save():
 f=file('fname','a')
 f.write(name.get()+'\n')
 f.write(age.get()+'\n')
 f.write(address.get()+'\n')

 widget = Button(win2, text='save', command=save).pack(side=LEFT)
 widget = Button(win2, text='quit',
command=win2.destroy).pack(side=RIGHT)
def area():
 global w,h
 win3 = Toplevel()
 widget = Label(win3, text='type hieght here: ').pack()
 h = DoubleVar()
 widget = Entry(win3, textvariable=h).pack()
 widget = Label(win3, text='type width here: ').pack()
 w = DoubleVar()
 widget = Entry(win3, textvariable=w).pack()
 widget = Button(win3, text=' calculate ',
command=cal).pack(side=BOTTOM, expand=YES, fill=BOTH)
 
 
fontentry = ('times', 20,
'bold') #
(font, size, style) defonision for fontentry. will be used later on in
the program
widget = Entry(win, text='type
here') # makes
entry point in 'win'
makemenu(win)
widget.config(font=fontentry)
# makes the font of entry equal to 'fontentry'
widget.config(bg='blue',
fg='yellow') #
makes the background (bg) black and the forground (text) yellow
widget.pack(side=TOP, expand=YES,
fill=BOTH) # 'packs' the
entry on top of win and expands and fill the Y axes
widget = Button(win, text="your name", command=newwin).pack(side=LEFT,
expand=YES, fill=BOTH)# creates button that says 'your name'. see
newwin callback for output.
widget = Button(win, text='quit all',
command=win.quit).pack(side=BOTTOM, expand=YES, fill=BOTH)
widget = Button(win, text='quit', command=win.destroy).pack(side=RIGHT,
expand=YES, fill=BOTH)
widget = Button(win, text='area', command=area).pack(side=LEFT,
expand=YES, fill=BOTH)
win.title('my program')

#end of program


-- 
geon




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


Re: [Tutor] time.sleep() error

2005-08-02 Thread geon
sunny sunny napsal(a):

Hi all,

I am using time.sleep to stop my program execution for some time. I
have imported time and am able to use it sucessfully in the main
program.

However if I use it in any function I get the following error:

the time.sleep(1) command generates this error :
TypeError : 'int' object is not callable 

  


Dont you actually have something like this?:

from time import *

# somewhere you use sleep like this
sleep=10

# and then
sleep(1)

# you get:
#sleep(1)
#TypeError: 'int' object is not callable

In this case you overwrite the original function sleep() with your/my
variable sleep
Solution: rename your/my variable sleep to f.e. notAwake=10 :-)

-- 
geon



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


Re: [Tutor] time.sleep() error

2005-08-02 Thread geon




geon napsal(a):

  sunny sunny napsal(a):

  
  
Hi all,

I am using time.sleep to stop my program execution for some time. I
have imported time and am able to use it sucessfully in the main
program.

However if I use it in any function I get the following error:

the time.sleep(1) command generates this error :
TypeError : 'int' object is not callable 

 


  
  
Dont you actually have something like this?:

from time import *

# somewhere you use sleep like this
sleep=10

# and then
sleep(1)

# you get:
#sleep(1)
#TypeError: 'int' object is not callable

In this case you "overwrite" the original function sleep() with your/my
variable sleep
Solution: rename your/my variable sleep to f.e. notAwake=10 :-)

  

Solution2: do not use from time import *. Prefer import time. Now you
know why :-)
Its not a waste of time still to rewrite you code in this way. 

-- 
geon




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


Re: [Tutor] Corrupt files

2005-08-02 Thread geon
Øyvind napsal(a):

Hello.

I have created a program that automatically downloads some files I need.
It can be .zip, .jpg, .mpg or .txt. However, a lot of the time urlretrieve
downloads the file, gives no error, but the downloaded file is corrupted.
I use a simple check for the size of the file. If it is way too small, I
automatically remove it. 


remove it and try to download it again, lets say , 3times until you get 
correct copy...

The files are ok on the server.

Is there some function/modulte that checks a files integrity wheter or not
the file is corrupt or not?

  


Until you are provided with, say, md5 checksum, there is no other way 
than comparing sizes, I think ...

-- 
geon


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


Re: [Tutor] Tkinter event for changing OptionMenu items

2005-07-21 Thread geon
Bernard Lebel wrote:

Hello,

I'm trying to bind an event to the changes made to an OptionMenu. Ie
the user chooses a different item, the rest of the Tk window gets
updated. To repopulate the window, a function would be called by the
binding.

Any suggestion?


var1 = StringVar()
var1.set( aTables[0] )
oOptionMenu = OptionMenu( oRoot, var1, aTables[0], *aTables[1:] )
sTableName = var1.get()
oOptionMenu.bind( 'Return', getTableColumns )
oOptionMenu.pack( fill = X )
  

I might know what you mean - binding optionMenu with say 
w.bind('ButtonPress-1', tisk) is too early, it is called not after 
the choice, but at the beginning, at clicking on the button.

I found curious solution, here it is: (maybe it could be done 
otherwise, I would like to know, too..):

from Tkinter import *

OPTIONS = [
egg,
bunny,
chicken
]

def callmeagain():
global state
   
if state!=var.get():
print var.get()
state=var.get()
root.after(1000, callmeagain)   

root = Tk()
var = StringVar()
var.set(OPTIONS[2]) # default value
state=var.get()

w = OptionMenu (root, var, *OPTIONS)
w.pack()

callmeagain()
root.mainloop()

Maybe this could help, too.

-- 
geon
Vyjímka je pravidlo. Rekurzivní.

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


Re: [Tutor] OFFLIST Re: replaying

2005-07-19 Thread geon
Brian van den Broek napsal(a):

 * There is no reason for questioner not to like to see my replay in 
 mailing list, I think. Why would he do it? Why should he want me just 
 for him?


 Sometimes I write privately. Sometimes people write me in private. 
 Most often in public, but sometimes people choose private. Like this 
 time. As Danny just wrote, this is not about Python, so I choose to 
 write a private email.

 I certainly have on other lists embarrassed :-[ myself by writing the 
 list when I meant to write a private email. That way, much 
 embarrassment and many people lose time. :-(

 The Tutor list way, if I get it wrong, little embarrassment and 2 
 people loose time. :-|

Sometimes , yes sometimes. The mailing list main mission should be to 
help all and not to support private messaging. In this case the 
statistics should come in. What is more often? To replay to the public 
or to the questioner?

I would forgive some private messages in maling list if I could read 
well done answers to troubles I do need. In this system, that support 
private replays, most of quality answers fade away.

I might reapeted myself: the mailing should support collaboration in 
public, sharing the wisdom. Not just solving trouble of a single man, 
not substitue private chats.

Of course, its all up to you, I open this thread only because it was so 
unusualy from all what I have seen up to now, that I just wanted to keep 
my habits.

Best wishes

-- 
geon
The Exlusion is Rule.


P.S. Replay to All sends two emails, not just one to list, and that is 
also not what I would like to do.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] ListBox in Tkinter

2005-07-18 Thread geon

Hi,

I would like to ask if it is possible to create such a listbox 
(attached) in TKinter itself or must have pmw ot tix...or ...


Thank you

--
geon
Vyjímka je pravidlo. Rekurzivní.


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


Re: [Tutor] ListBox in Tkinter

2005-07-18 Thread geon
Alan G napsal(a):

 I would like to ask if it is possible to create such a listbox 
 (attached) in TKinter itself or must have pmw ot tix...or ...


 PMW is written in Tkinter so yes, you could do it yourself but it is 
 not a native widget. Using PMW would be much easier!

I have just found this: http://effbot.org/tkinterbook/optionmenu.htm - 
that is nearly what I needed , just another design.
I think there are even other new widgets in new Tk/Tcl compared to the 
http://www.pythonware.com/library/tkinter/introduction/, but 
undocumented yet. Or poorly or only in original Tk documentation.


-- 
geon
Vyjímka je pravidlo. Rekurzivní.

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


[Tutor] replaying

2005-07-18 Thread geon
Hi,

Seems to me as very unuseful thing in this phorum, when I choose Replay 
to any message, the field to whom or Receiver is all the time not 
tutor@python.org but the original sender! Why? I can not understand that?

It sould be prefferably posted back to mailing list IMHO.


-- 
geon


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


Re: [Tutor] replaying

2005-07-18 Thread geon
Danny Yoo napsal(a):

However, there are significant downsides to enabling Reply-to munging:

http://www.unicom.com/pw/reply-to-harmful.html

I agree with most of those reasons, and so I won't enable Reply-to munging
unless there's a real overriding reason that trumps the ones listed on
that page.
  

Firtsly, sorry for my English.

Then I must must admit I didnt understand all what is written  in 
http://www.unicom.com/pw/reply-to-harmful.html and even I didnt read it 
attentively. Anyway the main reason IMHO why he decided to do so is 
having Elm (or even creating it?) which *easily* (I could say freedomly 
for lector=helper) supports both sending to mailing list and to 
original sender.

I got tho some reason against:

* I like to help. But I like to help all, All should have benefit from 
my replay. I know this from my own experience. Often, very often I 
browse the old messages and read what other wrote. Its also good when 
there are always the same questions My effort shouldnt die 
immendiately after sending my replay. The freedom of all is more that 
freedom of one.

* My TB doesnt support it. And maybe even others mail clients.Its really 
wasting of time to change the adress all the time. I like to help, but 
if the was more of such a inconvieniencies I would give it up. My time 
is expensive :-)

* There is no reason for questioner not to like to see my replay in 
mailing list, I think. Why would he do it? Why should he want me just 
for him?

To be able to read your replay pls use easy english ;-)

-- 
geon
Vyjímka je pravidlo. Rekurzivní.

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


Re: [Tutor] Tk -- which label clicked

2005-07-14 Thread geon
Ron Weidner napsal(a):

This doesn't work.  Not an error though. :)  What I'm
trying to do is get the text value of a label.

def icon_click(self, event=None):
  print event.widget.option_get(text, event.widget)

  

maybe event.widget['text'] ?
what else you can put into brackets?: print event.widget.keys()
what else can be after event.?: dir(event)


-- 
geon
Vyjímka je pravidlo. Rekurzivní.


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


Re: [Tutor] Why does my code show this?

2005-07-10 Thread geon




Nathan Pinno napsal(a):

  
  
  
  
cal_opt = int(raw_input("What option would you like: "))
if cal_opt == "1":
   ..

  



your problem is in these two lines (and even more, but if you solve
this, the others you get for free).
try run just these two lines and guess, think about what kind of
variable is in cal_opt.



  
elif cal_opt == "2":
 X = input("First number:" )
 Y = input("Second number:" )
 print X, "-", Y, "= ",X - Y
 cal_opt = int(raw_input("Option: "))

  

the other trouble might be on the last line - note that "if" is not
"while". :-)

before creating your own program would be better to go through some
nice tutorial, to get some experience.

nice pytime
geon



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


Re: [Tutor] And function

2005-07-05 Thread geon




gordnjen napsal(a):

  
  Message
  
  
  I need to write a program that
will do the following:
   
  Ask the user's age.
  If their age is below 1 yr old,
it prints "you are old enought to eat baby food"
  If they are over 16, it prints
"You are old enough to drive"
  If they are over 65, it prints
"You are old enough to drive" and "You are old enough to retire"
   
  If they are between the ages of
16 and 25, it prints "you are old enough to get a student discount".
   
  So far, I have this:
  

what about this:


   
  age =input("How old are you?")
if age16:
    print "You are old enough to drive!"
    if age65:
    print "You are old enough to retire!"
if age1:
   print "You are old enough to eat baby food!"
   
   
  

If's those are on the same logical level should be also on the same
vertical level :-)

Pavel



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