joe
joe

Reputation: 57

Taking in a user input to load a program

Within a revision application I'm developing, I'm looking to take in a user answer (of which area of revision they would like to focus upon) which will then load the specific area they need.

Would this require entry widgets?

This is the code I have so far:

instruction = tkinter.Label(roots, text= "'What would you like to revise?'\n")    
instruction.grid(row=0, column=0,sticky=W)
if int(answer) != int(entryWidget.get().strip()):
    tkMessageBox.showinfo("Answer", "INCORRECT!")
else:
    tkMessageBox.showinfo("Answer", "CORRECT!")

I apologize for the lack of code, but I'm unsure on how to develop it past this point without knowing how to load my alternate part of code from this point

part 2:

def Signup():
    global pwordE
    global nameE
    global roots

    roots = tkinter.Tk()
    roots.title("Computer Science Revision")
    roots.geometry("1000x1000")
    roots.wm_iconbitmap('favicon.ico')
    roots.configure(background="#a1dbcd")    

    photo= tkinter.PhotoImage(roots,file="ryu.gif")
    A = tkinter.Label(roots,image=photo)
    A.pack()    

    roots = tkinter.Tk()
    roots.title('Signup')
    instruction = tkinter.Label(roots, text= 'Please enter new Credentials\n')
    instruction.grid(row=0, column=0,sticky=W)

    nameL =  tkinter.Label(roots, text='New Username: ')
    pwordL =  tkinter.Label(roots, text='New Password: ')
    nameL.grid(row=1, column=0, sticky=W)
    pwordL.grid(row=2, column=0, sticky=W)
    nameE= tkinter.Entry(roots)
    pwordE = tkinter.Entry(roots, show='*')
    nameE.grid(row=1, column=1)
    pwordE.grid(row=2, column=1)

    signupButton = Button(roots, text='Signup', command=FSSignup)
    signupButton.grid(columnspan=2, sticky=W)
    roots.mainloop()

    roots.title("Computer Science Revision")
    roots.geometry("1000x1000")
    roots.wm_iconbitmap('favicon.ico')
    roots.configure(background="#a1dbcd")    

    photo= tkinter.PhotoImage(roots,file="ryu.gif")
    A = tkinter.Label(roots,image=photo)
    A.pack()

This part will not load with the rest of the login, how can I fix this?

Upvotes: 2

Views: 95

Answers (1)

Sundararajan
Sundararajan

Reputation: 704

I Hope you are asking something like this one.

import tkinter as tk

root = tk.Tk()
root.geometry("500x500+100+100")
def raise_frame(frame):
    frame.tkraise()

f1 = tk.Frame(root)
f2 = tk.Frame(root)
f3 = tk.Frame(root)
f4 = tk.Frame(root)

for frame in (f1,f2,f3,f4):
    frame.grid(row=0, column=0, sticky='news')

#Frame1

button1 = tk.Button(f1, text='English', command=lambda:raise_frame(f2)).pack()
button2 = tk.Button(f1, text='Maths', command=lambda:raise_frame(f3)).pack()
button3 = tk.Button(f1, text='Science', command=lambda:raise_frame(f4)).pack()


#Frame2

tk.Label(f2, text="English Revision").pack()
tk.Button(f2, text="HOME", command=lambda:raise_frame(f1)).pack()

#Frame3
tk.Label(f3, text="Maths Revision").pack()
tk.Button(f3, text="HOME", command=lambda:raise_frame(f1)).pack()

#Frame4
tk.Label(f4, text="Science Revision").pack()
tk.Button(f4, text="HOME", command=lambda:raise_frame(f1)).pack()

raise_frame(f1)
root.mainloop()

Upvotes: 2

Related Questions