Converting my script from MS-DOS to Tkinter ran in a problem.

Lamonte Harris pyth0nc0d3r at gmail.com
Fri Aug 24 19:46:39 EDT 2007


Ok my script works decent so far, but say in the add news menu, my window
dissapears right? but when i click add news on the main menu a new frame
gets added,  How can I remove the frames inside of my Toplevel?

import sys,os,urllib,urllib2,md5,random,string
from Tkinter import *
main = Tk()
main.withdraw()
false = 0
true = 1
logged_in = false
_user = ""
_pass = ""
_input1 = ""
_input2 = ""
url = "http://SITENAME.com/"
def dir_path():
    upath = os.path.realpath(os.path.dirname(sys.argv[0]))
    return upath
def md5_(hash):
    hash = md5.new(hash)
    hash = hash.hexdigest()
    return hash
class NewsSystem:
    def check_login(self):
        global e1,e2,master,_user,_pass,url,logged_in,true,choices
        _input1 = e1.get()
        _input2 = e2.get()
        domain = "%slogin.php?action=login" % (url)
        if _input1 != "" and _input2 != "":
            password = md5_(_input2)
            username = _input1
            send = {'username' : username,'password' : password }
            data = urllib.urlencode(send)
            request = urllib2.Request(domain,data)
            response = urllib2.urlopen(request)
            loggedin = response.read()
            if loggedin == "true":
                print "Logged in successful\n"
                logged_in = true
                _user = username
                _pass = password
                master.destroy()
                choices.deiconify()
            else:
                print "Login failed\n"
                logged_in = false
    def V(self):
        global v,textboxed,choices
        if v.get() == 1:
            choices.withdraw()
            textboxed.deiconify()
            self.addnews(textboxed)
        elif v.get() == 2:
            print v.get()
        elif v.get() == 3:
            print v.get()
        elif v.get() == 4:
            sys.exit()
        else:
            print "error";
    def addnews(self,main):
        menubar = Frame(main,relief=RAISED)
        menubar.pack(side=TOP)
        menuu = Menubutton(menubar,text="News Options")
        menuu.pack(side=LEFT)
        menuu.menu = Menu(menuu)
        menuu.menu.add_command(label='Add News')
        menuu.menu.add_command(label='Main Menu',command=self.main_menu)
        menuu.menu.add_command(label='Exit',command=self.close_me)
        menuu['menu'] = menuu.menu
        menuu.pack(side=LEFT)
        framx = Frame(main)
        framx.pack()

        self.textw = Text(framx,width=100,height=10)
        main.title("This is a textbox derr")
        scroll = Scrollbar(framx,command="scroll")
        self.textw.configure(yscrollcommand=scroll.set)
        scroll.pack(side=RIGHT)
        self.textw.pack()
    def close_me(self):
        sys.exit()
    def main_menu(self):
        global choices,textboxed
        choices.deiconify()
        textboxed.withdraw()
init = NewsSystem()
#Menu
choices = Toplevel()
choices.withdraw()
v = IntVar()
Radiobutton(choices, text="Add News", variable=v,value=1).pack(anchor=W)
Radiobutton(choices, text="Edit News", variable=v,value=2).pack(anchor=W)
Radiobutton(choices, text="Delete News", variable=v,value=3).pack(anchor=W)
Radiobutton(choices, text="Quit", variable=v,value=4).pack(anchor=W)
button = Button(choices, text="Action?",command=init.V).pack(anchor=W)
choices.title("What are your actions?")

#login
master = Toplevel()
Label(master, text="Username").grid(row=0, sticky=W)
Label(master, text="Password").grid(row=1, sticky=W)
e1 = Entry(master)
e2 = Entry(master,show="*")
e3 = Button(master,text="Login",command=init.check_login).grid(row=3,
sticky=W+E+S+N)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
master.geometry("%dx%d" % (300,300))
master.title("Login!")

#textbox
textboxed = Toplevel()
textboxed.withdraw()
main.mainloop()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070824/13a4f5e0/attachment.html>


More information about the Python-list mailing list