[Tkinter] problem

C

Club-B42

when i start opt_newlogin.py directly it works fine(outputs '1 1 1 1'),
but if i start it from options.py there is an error(outputs '').

========
opt_newlogin.py
========
from config import *
from Tkinter import *
from opt_newlogin import newlogin

def OptionsWindow():
"""
"""
root = Tk()

root.title(msg_OptionsWindowTitle)

b1 = Button(root, text = msgForgotPassword, width = 40).grid(padx = 5,
pady = 5, column = 0, row = 0)
b2 = Button(root, text = msgNewLogin, command = newlogin, width =
40).grid(padx = 5, pady = 5, column = 0, row = 1)

root.mainloop()

if __name__ == '__main__':
OptionsWindow()
========



========
options.py
========
from config import *
from Tkinter import *
import tkMessageBox, os.path

def create_new_account(login, password, secretq, secreta):
print login, password, secretq, secreta
if os.path.exists(os.path.join(data_path, login)):
tkMessageBox.showerror(title = msgError, message =
msgPasswordLoginExists)
elif login == '':
pass
else:
os.mkdir(os.path.join(data_path, login))
fd = file(os.path.join(data_path, login, data_info_file_name),
'wb')
fd.write(password + os.linesep)
fd.write(secretq + os.linesep)
fd.write(secreta + os.linesep)
fd.close()
tkMessageBox.showinfo(title = msgInfoAccountCreated, message =
msgInfoAccountCreated2)

def newlogin():
"""
"""
root = Tk()

root.title(msg_NewLoginWindowTitle)

l1 = Label(root, text = msgLogin).grid(padx = 5, pady = 5, column = 0,
row = 0, sticky = E)
l2 = Label(root, text = msgPassword).grid(padx = 5, pady = 5, column =
0, row = 1, sticky = E)
l3 = Label(root, text = msgConfirmPassword).grid(padx = 5, pady = 5,
column = 0, row = 2, sticky = E)
l4 = Message(root, text = msgKeyQuestion, width = 250).grid(padx = 5,
pady = 5, column = 0, row = 3, sticky = E)
l5 = Label(root, text = msgKeyQuestionAnswer).grid(padx = 5, pady = 5,
column = 0, row = 4, sticky = E)

v1 = StringVar()
v2 = StringVar()
v3 = StringVar()
v4 = StringVar()
v5 = StringVar()
e1 = Entry(root, width = 50, textvariable = v1)
e1.grid(padx = 5, pady = 5, column = 1, row = 0)
e1.focus_force()
e2 = Entry(root, width = 50, textvariable = v2, show = '*')
e2.grid(padx = 5, pady = 5, column = 1, row = 1)
e3 = Entry(root, width = 50, textvariable = v3, show = '*')
e3.grid(padx = 5, pady = 5, column = 1, row = 2)
e4 = Entry(root, width = 50, textvariable = v4)
e4.grid(padx = 5, pady = 5, column = 1, row = 3)
e5 = Entry(root, width = 50, textvariable = v5, show = '*')
e5.grid(padx = 5, pady = 5, column = 1, row = 4)

def b1_cmd():
if v2.get() <> v3.get():
tkMessageBox.showerror(title = msgError, message =
msgPasswordConfirmError)
print v1.get(), v2.get(), v4.get(), v5.get()
create_new_account(v1.get(), v2.get(), v4.get(), v5.get())

b1 = Button(root, text = msgCreateNewLoginButton, command =
b1_cmd).grid(padx = 5, pady = 5, column = 0, row = 5)
b2 = Button(root, text = msgCancelButton, command =
root.destroy).grid(padx = 5, pady = 5, column = 1, row = 5)

root.mainloop()


if __name__ == '__main__':
newlogin()
========


========
config.py
========
# codepage = cp1251
#
#
#


def u(s):
return unicode(s, 'cp1251')


msgMainWindowTitle = u('íÅÎÅÄÖÅÒ ÓÏÈÒÁÎÑÌÏË ËÌÕÂÁ B 4\\2')
msgLogin = u('ìÏÇÉÎ')
msgPassword = u('ðÁÒÏÌØ')
msgGameNumber = u('îÏÍÅÒ ÉÇÒÙ')
msgSaveButton = u(' óÏÈÒÁÎÉÔØ ')
msgLoadButton = u(' úÁÇÒÕÚÉÔØ ')
msgOptionsButton = u(' äÏÐÏÌÎÉÔÅÌØÎÏ ')

msg_OptionsWindowTitle = u('äÏÐÏÌÎÉÔÅÌØÎÏ')
msgForgotPassword = u(' úÁÂÙÌ ÐÁÒÏÌØ ')
msgNewLogin = u(' îÏ×ÙÊ ÌÏÇÉÎ ')

msg_NewLoginWindowTitle = u('óÏÚÄÁÎÉÅ ÎÏ×ÏÇÏ ÌÏÇÉÎÁ')
msgConfirmPassword = u('åÝÅ ÒÁÚ ÐÁÒÏÌØ')
msgKeyQuestion = u('óÅËÒÅÔÎÙÊ ×ÏÐÒÏÓ - ÏÔ×ÅÔ ÎÁ
ËÏÔÏÒÙÊ ÚÎÁÅÔÅ ÔÏÌØËÏ ×Ù - ÎÁ ÓÌÕÞÁÊ, ÅÓÌÉ ×Ù ÚÁÂÕÄÅÔÅ ÐÁÒÏÌØ')
msgKeyQuestionAnswer = u('ïÔ×ÅÔ ÎÁ ÓÅËÒÅÔÎÙÊ ×ÏÐÒÏÓ')
msgCreateNewLoginButton = u(' óÏÚÄÁÔØ ')
msgCancelButton = u(' ïÔÍÅÎÁ ')
msgError = u('ïÛÉÂËÁ')
msgPasswordConfirmError = u('ðÁÒÏÌÉ ÎÅ ÓÏ×ÐÁÄÁÀÔ.')
msgPasswordLoginExists = u('ôÁËÏÊ ÌÏÇÉÎ ÕÖÅ ÓÕÝÅÓÔ×ÕÅÔ.')
msgInfoAccountCreated = u('ìÏÇÉÎ ÕÓÐÅÛÎÏ ÚÁÒÅÇÅÓÔÒÉÒÏ×ÁÎ')
msgInfoAccountCreated2 = u('÷Ù ÍÏÖÅÔÅ ÉÓÐÏÌØÚÏ×ÁÔØ ÜÔÏÔ ÌÏÇÉÎ
É ÐÁÒÏÌØ ÄÌÑ ÓÏÈÒÁÎÅÎÉÑ É ×ÏÓÔÁÎÏ×ÌÅÎÉÑ Ó×ÏÉÈ ÓÏÈÒÁÎÑÌÏË.')

msgInvalidGameNumber = u('îÅÐÒÁ×ÉÌØÎÙÊ ÎÏÍÅÒ ÉÇÒÙ.')
msgInvalidPassword = u('îÅÐÒÁ×ÉÌØÎÙÊ ÐÁÒÏÌØ.')
msgInvalidLogin = u('ìÏÇÉÎ ÎÅ ÓÕÝÅÓÔ×ÕÅÔ.')
msgSaveError = u('îÅ ÕÄÁÌÏÓØ ÓËÏÐÉÒÏ×ÁÔØ.')
msgSuccess = u('óÏÈÒÁÎÅÎÏ')
msgSuccessCopy = u('óÏÈÒÁÎÑÌËÉ ÕÓÐÅÛÎÏ ÓÏÈÒÁÎÅÎÙ ÎÁ
ÓÅÒ×ÅÒ, ÔÅÐÅÒØ ×Ù ÍÏÖÅÔÅ ×ÏÓÓÔÁÎÏ×ÉÔØ ÉÈ ÎÁ ÌÀÂÏÍ ËÏÍÐØÀÔÅÒÅ.')


data_path = '\\\\192.168.1.1\\óÏÈÒÁÎÑÌËÉ\\'
data_info_file_name = 'info'

info_path = 'info'
========
 
J

Jeff Epler

These lines
if __name__ == '__main__':
OptionsWindow()
mean "if this source code is the main program (not an imported module),
call OptionsWindow()". So the behavior should be different when the
source code is the main program ('python opt_newlogin.py') and when it's
imported ('python -c "import opt_newlogin"')

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFB/FvxJd01MZaTXX0RAl2AAJ9iWlFnPqVt30HvP37aJGgTQDSVYACaAvY+
UOjhSVekewUunonNAEZOMko=
=vqW0
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top