File write() problem

2006-12-27 Thread apriebe47
Alright, I realize this is probably very basic to be posted on this
newsgroup but I cannot figure out what is causing my problem. Here is
the code I am using below:

from getpass import getpass

configfile = file('config.txt', 'w')
serverPassword = configfile.readline()
if serverPassword == '':
print Server warning: No password has been set!
pwd1 = getpass(New Password: )
pwd2 = getpass(Confirm Password: )
while pwd1 != pwd2:
print Passwords did not match.
pwd1 = getpass(New Password: )
pwd2 = getpass(Confirm Password: )
print Password set. Storing to file
configfile.write(pwd2)
serverPassword = configfile.readline()
configfile.close()

Now when I look at the file, I can see the password that I had typed
in, but there are also a bunch of symbols that are added to the text
file as well. My question is how can I write just the password to the
text file and not any extra 'garbage'. Thanks!

Andrew

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File write() problem

2006-12-27 Thread apriebe47
Marc 'BlackJack' Rintsch wrote:

  configfile = file('config.txt', 'w')
  serverPassword = configfile.readline()

Hrm. When I run the code that I posted I don't seem to get those
errors.

 Please post the exact code you have trouble with.  Don't retype it -- copy
 and paste it.

from getpass import getpass

configfile = file('config.txt', 'w')
serverPassword = configfile.readline()
if serverPassword == '':
   print Server warning: No password has been set!
   pwd1 = getpass(New Password: )
   pwd2 = getpass(Confirm Password: )
   while pwd1 != pwd2:
   print Passwords did not match.
   pwd1 = getpass(New Password: )
   pwd2 = getpass(Confirm Password: )
   print Password set. Storing to admin/config...
   configfile.write(pwd2)
   serverPassword = configfile.readline()
   configfile.close()

Again I tested the code before I posted and I get no errors, just not
the result I am looking for in the text file. Thanks for taking the
time to look at it.

Andrew

-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter binding and keyboard hardware settings (WinXP)

2006-07-10 Thread apriebe47
Hello,

I have created a simple canvas in Tkinter to display a number of
PhotoImages, I then bind a key (in my case, Up) to start a loop that
plays through a list of PhotoImages to make it an animation of sorts.
What I noticed is, after holding down the key for a certain time, it
would not loop through all 6 animations, instead it would just go
through the first 2 and reset it self. I changed the key bind to
Button-1 and did not encounter this problem. I then went into my
keyboard hardware settings and changed the repeat rate to the longest
delay and the repeat delay to the longest delay. This improved it some
what, but I don't think it is practical to do this everytime I start up
the program. My question is, is there a way to bind a key so as to make
it ignore the keyboard's delay and repeat rate settings? Here's the
code just so you can get an idea:

# GIF Animation Test

from Tkinter import *
from time import sleep

class GIF:
def __init__(self, root):
self.root = root
self.canvas = Canvas(root, bg=white, width=225, height=200)
self.canvas.pack()
self.cronoUpImageList =[
 cronoup1.gif, cronoup2.gif, cronoup3.gif,
 cronoup4.gif, cronoup5.gif, cronoup6.gif]
self.gifImage = PhotoImage(file=self.cronoUpImageList[0])
self.cronoDefUp = PhotoImage(file=cronodefup.gif)
self.drawImage = self.canvas.create_image(112.5, 100, image=
  self.cronoDefUp)
self.canvas.bind(Up, self.keyboardPrsUp)
self.canvas.bind(Down, self.keyboardRlsUp)

def keyboardPrsUp(self, event):
self.canvas.delete(self.drawImage)
self.counter = 0
self.killEvent = False
while self.killEvent != True:
print self.cronoUpImageList[self.counter]
self.gifImage =
PhotoImage(file=self.cronoUpImageList[self.counter])
self.drawImage = self.canvas.create_image(112.5, 100,
image=
  self.gifImage)
self.counter = self.counter + 1
if self.counter  5:
self.counter = 0
self.canvas.update()
sleep(.05)


def keyboardRlsUp(self, event):
self.counter = 0
self.killEvent = True
self.canvas.delete(self.drawImage)
self.drawImage = self.canvas.create_image(112.5, 100, image=
  self.cronoDefUp)


root = Tk()
root.title(GIF Animation Test)
app = GIF(root)
root.mainloop()

-- 
http://mail.python.org/mailman/listinfo/python-list