[Tkinter] problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Club-B42

    #1

    [Tkinter] problem

    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_ OptionsWindowTi tle)

    b1 = Button(root, text = msgForgotPasswo rd, 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_acco unt(login, password, secretq, secreta):
    print login, password, secretq, secreta
    if os.path.exists( os.path.join(da ta_path, login)):
    tkMessageBox.sh owerror(title = msgError, message =
    msgPasswordLogi nExists)
    elif login == '':
    pass
    else:
    os.mkdir(os.pat h.join(data_pat h, login))
    fd = file(os.path.jo in(data_path, login, data_info_file_ name),
    'wb')
    fd.write(passwo rd + os.linesep)
    fd.write(secret q + os.linesep)
    fd.write(secret a + os.linesep)
    fd.close()
    tkMessageBox.sh owinfo(title = msgInfoAccountC reated, message =
    msgInfoAccountC reated2)

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

    root.title(msg_ NewLoginWindowT itle)

    l1 = Label(root, text = msgLogin).grid( padx = 5, pady = 5, column = 0,
    row = 0, sticky = E)
    l2 = Label(root, text = msgPassword).gr id(padx = 5, pady = 5, column =
    0, row = 1, sticky = E)
    l3 = Label(root, text = msgConfirmPassw ord).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 = msgKeyQuestionA nswer).grid(pad x = 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.sh owerror(title = msgError, message =
    msgPasswordConf irmError)
    print v1.get(), v2.get(), v4.get(), v5.get()
    create_new_acco unt(v1.get(), v2.get(), v4.get(), v5.get())

    b1 = Button(root, text = msgCreateNewLog inButton, command =
    b1_cmd).grid(pa dx = 5, pady = 5, column = 0, row = 5)
    b2 = Button(root, text = msgCancelButton , command =
    root.destroy).g rid(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')


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

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

    msg_NewLoginWin dowTitle = u('óÏÚÄÁÎÉÅ ÎÏ×ÏÇÏ ÌÏÇÉÎÁ')
    msgConfirmPassw ord = u('åÝÅ ÒÁÚ ÐÁÒÏÌØ')
    msgKeyQuestion = u('óÅËÒÅÔÎÙÊ ×ÏÐÒÏÓ - ÏÔ×ÅÔ ÎÁ
    ËÏÔÏÒÙÊ ÚÎÁÅÔÅ ÔÏÌØËÏ ×Ù - ÎÁ ÓÌÕÞÁÊ, ÅÓÌÉ ×Ù ÚÁÂÕÄÅÔÅ ÐÁÒÏÌØ')
    msgKeyQuestionA nswer = u('ïÔ×ÅÔ ÎÁ ÓÅËÒÅÔÎÙÊ ×ÏÐÒÏÓ')
    msgCreateNewLog inButton = u(' óÏÚÄÁÔØ ')
    msgCancelButton = u(' ïÔÍÅÎÁ ')
    msgError = u('ïÛÉÂËÁ')
    msgPasswordConf irmError = u('ðÁÒÏÌÉ ÎÅ ÓÏ×ÐÁÄÁÀÔ.')
    msgPasswordLogi nExists = u('ôÁËÏÊ ÌÏÇÉÎ ÕÖÅ ÓÕÝÅÓÔ×ÕÅÔ.')
    msgInfoAccountC reated = u('ìÏÇÉÎ ÕÓÐÅÛÎÏ ÚÁÒÅÇÅÓÔÒÉÒÏ×ÁÎ ')
    msgInfoAccountC reated2 = u('÷Ù ÍÏÖÅÔÅ ÉÓÐÏÌØÚÏ×ÁÔØ ÜÔÏÔ ÌÏÇÉÎ
    É ÐÁÒÏÌØ ÄÌÑ ÓÏÈÒÁÎÅÎÉÑ É ×ÏÓÔÁÎÏ×ÌÅÎÉÑ Ó×ÏÉÈ ÓÏÈÒÁÎÑÌÏË.')

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


    data_path = '\\\\192.168.1. 1\\óÏÈÒÁÎÑÌËÉ\\ '
    data_info_file_ name = 'info'

    info_path = 'info'
    ========
  • Jeff Epler

    #2
    Re: [Tkinter] problem

    These lines[color=blue]
    > if __name__ == '__main__':
    > OptionsWindow()[/color]
    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/FvxJd01MZaTXX0R Al2AAJ9iWlFnPqV t30HvP37aJGgTQD SVYACaAvY+
    UOjhSVekewUunon NAEZOMko=
    =vqW0
    -----END PGP SIGNATURE-----

    Comment

    Working...