資源簡介
設計一個GUI界面的ATM系統,該系統可以實現現實生活中ATM機器的大部分功能,涉及到插卡,退卡,取款,存款等操作。
用戶插卡:選擇已有卡號,輸入密碼進行登錄。
ATM系統功能:查詢余額;
轉賬:輸入乙方銀行卡和轉賬金額;
存款;
流水記錄:查詢銀行卡賬單
取款;
退卡。
代碼片段和文件信息
import?tkinter?as?tk
from?tkinter?import?ttk
import?datetime
import?tkinter.messagebox
class?Windows:
????user_info?=?{}
????def?__init__(self?master=None):
????????self.atm?=?ATM()
????????self.master?=?master
????????self.choose_card()
????????self.pwd_judge?=?0
????def?choose_card(self):
????????self.root1?=?tk.frame(self.master)
????????self.root1[‘width‘]?=?300
????????self.root1[‘height‘]?=?100
????????self.lbl1?=?tk.Label(self.root1?text=‘銀行卡:‘?font=(‘microsoft?yahei‘?10))
????????self.lbl1.place(x=25?y=30)
????????self.cbox1?=?ttk.Combobox(self.root1)
????????self.cbox1[‘values‘]?=?self.atm.choose_card()
????????self.cbox1.place(x=80?y=32)
????????self.btn1?=?tk.Button(self.root1?text=‘確認‘?font=(‘microsoft?yahei‘?10)
??????????????????????????????command=lambda:?self.confirm(self.cbox1.get()))
????????self.btn1.place(x=250?y=28)
????????self.root1.pack()
????def?confirm(self?user):
????????if?user?!=?‘‘:
????????????self.root1.destroy()
????????????self.root1?=?tk.frame(self.master)
????????????self.root1[‘width‘]?=?300
????????????self.root1[‘height‘]?=?100
????????????self.lbl2?=?tk.Label(self.root1?text=‘賬戶:‘?+?user?font=(‘microsoft?yahei‘?10))
????????????self.lbl2.place(x=25?y=20)
????????????self.lbl3?=?tk.Label(self.root1?text=‘密碼:‘?font=(‘microsoft?yahei‘?10))
????????????self.lbl3.place(x=25?y=40)
????????????self.entry1?=?tk.Entry(self.root1?show=“*“)
????????????self.entry1.place(x=70?y=40)
????????????self.btn2?=?tk.Button(self.root1?text=‘確認‘?font=(‘microsoft?yahei‘?10)?width=10
??????????????????????????????????command=lambda:?self.T_F(user?self.entry1.get()))
????????????self.btn2.place(x=90?y=70)
????????????self.root1.pack()
????????else:
????????????tkinter.messagebox.showinfo(‘提示‘?‘請選擇卡號!‘)
????def?T_F(self?user?pwd):
????????self.flag?=?False
????????for?i?in?self.atm.Card:
????????????if?i[‘user‘]?==?int(user):
????????????????Windows.user_info?=?i
????????????????if?i[‘pwd‘]?==?int(pwd):
????????????????????self.flag?=?True
????????????????????break
????????if?self.flag:
????????????self.c_to_f()
????????elif?self.pwd_judge?==?2:
????????????tkinter.messagebox.showinfo(‘提示‘?‘密碼錯誤3次,銀行卡凍結至明天!‘)
????????????exit()
????????else:
????????????self.pwd_judge?+=?1
????????????tkinter.messagebox.showinfo(‘提示‘?‘密碼錯誤!你還有{0}次機會‘.format(3?-?self.pwd_judge))
????def?c_to_f(self):
????????tkinter.messagebox.showinfo(‘提示‘?‘即將進入atm系統‘)
????????self.root1.destroy()
????????self.function_board()
????def?function_board(self):
????????if?self.root1:
????????????self.root1.destroy()
????????self.root1?=?tk.frame(self.master)
????????self.root1[‘width‘]?=?300
????????self.root1[‘height‘]?=?100
????????self.buttons?=?[[“查詢余額“?“存款“?“取款“]
????????????????????????[“轉賬“?“流水記錄“?“退卡“]]
????????for?r?in?range(2):
????????????for?c?in?range(3):
????????????????def?cmd(key=self.buttons[r][c]):
????????????????????self.cli
- 上一篇:PYTHON的winio
- 下一篇:python GUI井字棋
評論
共有 條評論