我为我的ATM模拟程序创建了一个登录页框架,我无法使我的登录按钮正确运行。我的登录页面有两个输入字段,帐号和PIN号码。我希望能够打开一个新的框架窗口,我创建了一个名为“欢迎页面”,如果帐户号码与我创建的帐户号码匹配,如果PIN号码与我创建的PIN号码匹配。如果没有,它将保留在登录页面上。这是我目前为止的全部剧本#!/usr/细心的音响/python
from tkinter import *
from tkinter import ttk
import tkinter as tk
Large_Font = (\”Verdana\”, 18)
Small_Font = (\”Verdana\”, 12)
act = \’1234567\’
pin = \’1234\’
class ATM(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, \”ATM Simulator\”)
#tk.Tk.iconbitmap(self, default = \”atm.ico\”)
container = tk.Frame(self)
container.pack(side = \”top\”, fill =\”both\”, expand =True)
container.grid_rowconfigure(100, weight=1)
container.grid_columnconfigure(100, weight=1)
self.frames = {}
for i in (LogIn, WelcomePage, Checking, Savings, Transfer):
frame = i(container, self)
self.frames[i] = frame
frame.grid(row= 100, column = 100, sticky= \”nsew\”)
self.show_frame(LogIn)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class LogIn(tk.Frame):
def __init__(self, parent, controller):
global actEntry
global pinEntry
tk.Frame.__init__(self, parent)
logLabel = ttk.Label(self, text = \”Login With Your Account Number and Pin\”, font = Large_Font)
logLabel.pack(side = TOP, anchor = N, expand = YES)
actLabel = Label(self, text = \’Account Number:\’)
pinLabel = Label(self, text = \’PIN Number: \’)
actEntry = Entry(self)
pinEntry = Entry(self, show =\”*\”)
actLabel.pack(pady =10, padx = 10, side = TOP, anchor = N)
pinLabel.pack(pady =5, padx = 10, side = TOP, anchor = S)
actEntry.pack(pady =10, padx = 10, side = TOP, anchor = N)
pinEntry.pack(pady =5, padx = 10, side = TOP, anchor = S)
# runs the \’LoginCheck\’ function
logInButton = ttk.Button(self, text = \”Enter\”,
command = self.LogInCheck)
logInButton.pack(side = TOP, anchor = S)
quitButton = ttk.Button(self, text = \”Quit\”, command = quit)
quitButton.pack(side = BOTTOM, anchor = S)
def LogInCheck(self):
actNum = actEntry.get()
pinNum = pinEntry.get()
if actNum == act and pinNum == pin:
return
self.show_frame(WelcomePage)
else:
return
self.show_frame(LogIn)
class WelcomePage(tk.Frame):
#Welcome Page Window
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = ttk.Label(self, text = \”Welcome to the ATM Simulator\”, font = Large_Font)
label.pack(pady=100, padx=100)
checkButton = ttk.Button(self, text = \”Checking Account\”,
command = lambda: controller.show_frame(Checking))
checkButton.pack()
saveButton = ttk.Button(self, text = \”Savings Account\”,
command = lambda: controller.show_frame(Savings))
saveButton.pack()
transButton = ttk.Button(self, text = \”Transfer Funds\”,
command = lambda: controller.show_frame(Transfer))
transButton.pack()
quitButton = ttk.Button(self, text = \”End Transaction\”, command = self.client_exit)
quitButton.pack()
def client_exit(self):
exit()
class Checking(tk.Frame):
#Checking Account Window
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text = \”Checking Account\”, font = Large_Font)
label.pack(pady=100, padx=100)
homeButton = ttk.Button(self, text = \”Back to Home Page\”,
command = lambda: controller.show_frame(WelcomePage))
homeButton.pack()
quitButton = ttk.Button(self, text = \”End Transaction\”, command = quit)
quitButton.pack()
class Savings(tk.Frame):
#Savings Account Window
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = ttk.Label(self, text = \”Savings Account\”, font = Large_Font)
label.pack(pady=100, padx=100)
homeButton = ttk.Button(self, text = \”Back to Home Page\”,
command = lambda: controller.show_frame(WelcomePage))
homeButton.pack()
quitButton = ttk.Button(self, text = \”End Transaction\”, command = quit)
quitButton.pack()
class Transfer(tk.Frame):
活动:慈云数据爆款香港服务器,CTG+CN2高速带宽、快速稳定、平均延迟10+ms 速度快,免备案,每月仅需19元!! 点击查看 #Transfer Funds Window
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = ttk.Label(self, text = \”Transfer Funds\”, font = Large_Font)
label.pack(pady=100, padx=100)
homeButton = ttk.Button(self, text = \”Back to Home Page\”,
command = lambda: controller.show_frame(WelcomePage))
homeButton.pack()
quitButton = ttk.Button(self, text = \”End Transaction\”, command = quit)
quitButton.pack()
atm = ATM()
atm.mainloop()
默认帐号1234567和我创建的默认pin是1234。我计划使用pickle模块创建一个包含帐号和pin的字典,但是现在我只想用这些帐号登录。我欢迎任何关于如何实现这一点和如何改进我的脚本的建议,谢谢!在
44059029
《python登 tk页面跳转使用Tkin的Python登录页面,登录页面跳转到index》来自互联网同行内容,若有侵权,请联系我们删除!
还没有评论,来说两句吧...