Skip to main content
 首页 » 编程设计

python之接收用户输入以加载程序

2024年10月01日8think

在我正在开发的修订应用程序中,我希望获得用户答案(他们希望关注修订的哪个区域),然后加载他们需要的特定区域。

这需要入口小部件吗?

这是我目前的代码:

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!") 

对于缺少代码,我深表歉意,但我不确定如何开发它超过这一点,而不知道如何从这一点加载我的代码的替代部分

第 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() 

这部分不会随着登录的其余部分一起加载,我该如何解决这个问题?

请您参考如下方法:

我希望你问的是这样的问题。

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()