?
前言
一个基于python和MySQL的飞机大战小游戏,包含了管理员和用户的操作。
一、创建数据库
用Navicat创建如图所示数据库
?
二、python项目
1.运行结果
1.用户注册
2.用户查询
?3.管理员登陆
4. 完整操作
?最后来一遍完整视频演示(由于编码问题建议下载观看)
2.新建Login.py
Login.py
# -*- coding: UTF-8 -*-
"""
@author:林枫
@file:3.py
@time:2021/06/07
"""
import pymysql
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
from tkinter.messagebox import *
from game import *
import pygame
class My_Gui():
def __init__(self, main_screen):
self.main_screen = main_screen
def set_init_window(self):
self.main_screen.geometry("1442x700")
self.main_screen.title("登陆界面")
self.bg = PhotoImage(file='background.png')
Label(image=self.bg).place(x=0, y=0)
Label(text="欢迎登录飞机大战游戏", font=("宋体", 20)).place(x=580, y=100)
Label(text="账号", font=("宋体", 15)).place(x=450, y=250)
Label(text="密码", font=("宋体", 15)).place(x=450, y=350)
self.username_verify = StringVar()
self.password_verify = StringVar()
self.username_login_entry = Entry(self.main_screen, textvariable=self.username_verify, width=45,
font=("宋体", 15))
self.username_login_entry.place(x=500, y=250)
self.password_login_entry = Entry(self.main_screen, textvariable=self.password_verify, show='*', width=45,
font=("宋体", 15))
self.password_login_entry.place(x=500, y=350)
Button(text="用户登录", width="10", font=("宋体", 15), command=self.login_verify).place(x=650, y=400)
Button(text="管理员登录", width="10", font=("宋体", 15), command=self.Admin_login_verify).place(x=450, y=400)
Button(text="用户注册", width="10", font=("宋体", 15), command=self.register).place(x=840, y=400)
self.main_screen.mainloop()
def login_verify(self):
self.username1 = self.username_verify.get()
self.password1 = self.password_verify.get()
conn = pymysql.connect(host='localhost', user='root', passwd='123456', db='testdb', port=3306,
charset='utf8')
cur = conn.cursor()
select_sql = "select pw from user WHERE un=%s"
cur.execute(select_sql, [self.username1])
result = cur.fetchone()
if len(self.username1) == 0:
messagebox.showinfo("错误", "请输入账号!")
cur.close()
conn.close()
elif result is None:
cur.close()
conn.close()
messagebox.showinfo("失败", "该账号未注册!")
self.password_login_entry.delete(0, END)
self.username_login_entry.delete(0, END)
else:
if result[0] == self.password1:
cur.close()
conn.close()
messagebox.showinfo("成功", "登录成功")
self.username_login_entry.delete(0, END)
self.password_login_entry.delete(0, END)
self.login_sucess()
elif result[0] != self.password1:
cur.close()
conn.close()
messagebox.showinfo("失败", "密码错误!")
self.password_login_entry.delete(0, END)
def login_sucess(self):
self.main_screen.destroy()
conn = pymysql.connect(host='localhost', user='root', passwd='123456', db='testdb', port=3306,
charset='utf8')
cur = conn.cursor()
select_sql = "select id from user WHERE un=%s"
cur.execute(select_sql, [self.username1])
i = cur.fetchone()[0]
select_sql = "select code, time from code_lable WHERE userid=%s"
cur.execute(select_sql, [i])
data = cur.fetchall()
data = list(data)
data = list(reversed(data))
print(data)
max_list = []
data_list = []
for x in data:
max_list.append(int(x[0]))
self.user_screen1 = Tk()
self.user_screen1.geometry("1442x700")
self.user_screen1.title("用户界面")
self.bg = PhotoImage(file='background.png')
Label(self.user_screen1, image=self.bg).place(x=0, y=0)
Label(self.user_screen1, text="亲爱的玩家:" + self.username1 + ' 你好', font=("宋体", 20)).place(x=565, y=30)
self.columns = ("序号", "得分", "时间", "序号1", "得分1", "时间1", "序号2", "得分2", "时间2")
self.tree = ttk.Treeview(self.user_screen1, height=20, show="headings", columns=self.columns) # 隐藏首列
self.tree.column("序号", width=60) # 表示列,不显示
self.tree.column("得分", width=170) # 表示列,不显示
self.tree.column("时间", width=170) # 表示列,不显示
self.tree.column("序号1", width=60) # 表示列,不显示
self.tree.column("得分1", width=170) # 表示列,不显示
self.tree.column("时间1", width=170) # 表示列,不显示
self.tree.column("序号2", width=60) # 表示列,不显示
self.tree.column("得分2", width=170) # 表示列,不显示
self.tree.column("时间2", width=170) # 表示列,不显示
self.tree.place(x=130, y=150)
self.tree.heading("序号", text='序号', anchor=CENTER)
self.tree.heading("得分", text='得分', anchor=CENTER)
self.tree.heading("时间", text='时间', anchor=CENTER)
self.tree.heading("序号1", text='序号', anchor=CENTER)
self.tree.heading("得分1", text='得分', anchor=CENTER)
self.tree.heading("时间1", text='时间', anchor=CENTER)
self.tree.heading("序号2", text='序号', anchor=CENTER)
self.tree.heading("得分2", text='得分', anchor=CENTER)
self.tree.heading("时间2", text='时间', anchor=CENTER)
if len(max_list) == 0:
Label(self.user_screen1, font=("宋体", 15), text="您暂无游戏数据,快开始游戏吧!").place(x=560, y=100)
elif len(max_list) > 0 and len(max_list) <= 20:
Label(self.user_screen1, font=("宋体", 15), text="您的最高分为:" + str(max(max_list)) + '分').place(x=580, y=100)
for i in range(0, len(max_list)):
self.tree.insert("", i, values=(i + 1, data[i][0], data[i][1]))
elif len(max_list) > 20 and len(max_list) <= 40:
Label(self.user_screen1, font=("宋体", 15), text="您的最高分为:" + str(max(max_list)) + '分').place(x=580, y=100)
for i in range(0, len(max_list) - 20):
self.tree.insert("", i,
values=(i + 1, data[i][0], data[i][1], i + 21, data[i + 20][0], data[i + 20][1]))
for x in range(i + 1, 21):
self.tree.insert("", x, values=(x + 1, data[x][0], data[x][1]))
elif len(max_list) > 40 and len(max_list) <= 60:
Label(self.user_screen1, font=("宋体", 15), text="您的最高分为:" + str(max(max_list)) + '分').place(x=580, y=100)
for i in range(0, len(max_list) - 40):
self.tree.insert("", i, values=(
i + 1, data[i][0], data[i][1], i + 21, data[i + 20][0], data[i + 20][1], i + 41, data[i + 40][0],
data[i + 40][1]))
for x in range(i + 1, 21):
self.tree.insert("", x,
values=(x + 1, data[x][0], data[x][1], x + 21, data[x + 20][0], data[x + 20][1]))
else:
Label(self.user_screen1, font=("宋体", 15), text="您的最高分为:" + str(max(max_list)) + '分').place(x=580, y=100)
for i in range(20):
self.tree.insert("", i, values=(
i + 1, data[i][0], data[i][1], i + 21, data[i + 20][0], data[i + 20][1], i + 41, data[i + 40][0],
data[i + 40][1]))
cur.close()
conn.close()
Button(self.user_screen1, text="开始游戏", width=10, font=("宋体", 15), command=self.Destroy3).place(x=200, y=600)
Button(self.user_screen1, text="返回首页", width=10, font=("宋体", 15), command=self.Destroy2).place(x=1120, y=600)
self.user_screen1.mainloop()
def register_user(self):
self.username_info = self.username_entry.get()
self.password_info = self.password_entry.get()
conn = pymysql.connect(host='localhost', user='root', passwd='123456', db='testdb', port=3306,
charset='utf8')
cur = conn.cursor()
select_sql = "select un from user WHERE un=%s"
cur.execute(select_sql, [self.username_info])
result = cur.fetchone()
if len(self.username_info) == 0:
messagebox.showinfo("错误", "请输入账号!")
cur.close()
conn.close()
elif len(self.password_info) == 0:
messagebox.showinfo("错误", "请输入密码!")
cur.close()
conn.close()
elif result is None:
sql = 'insert into user(un,pw)' \
'values("%s","%s")' % \
(self.username_info, self.password_info)
try:
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
except:
conn.rollback()
self.username_entry.delete(0, END)
self.password_entry.delete(0, END)
messagebox.showinfo("成功", "注册成功!")
else:
cur.close()
conn.close()
messagebox.showinfo("失败", "该账号已被注册!")
self.password_entry.delete(0, END)
self.username_entry.delete(0, END)
def register(self):
self.username = StringVar()
self.password = StringVar()
self.main_screen.destroy()
self.register_screen = Tk()
self.register_screen.geometry("1442x700")
self.register_screen.title("注册界面")
self.bg = PhotoImage(file='background.png')
Label(self.register_screen, image=self.bg).place(x=0, y=0)
Label(self.register_screen, text="欢迎来到注册界面", font=("宋体", 20)).place(x=580, y=100)
self.username_lable = Label(self.register_screen, font=("宋体", 15), text="账号")
self.username_lable.place(x=450, y=250)
self.username_entry = Entry(self.register_screen, textvariable=self.username, width=45, font=("宋体", 15))
self.username_entry.place(x=500, y=250)
self.password_lable = Label(self.register_screen, font=("宋体", 15), text="密码")
self.password_lable.place(x=450, y=350)
self.password_entry = Entry(self.register_screen, textvariable=self.password, show='*', width=45,
font=("宋体", 15))
self.password_entry.place(x=500, y=350)
Button(self.register_screen, text="注册", width=10, font=("宋体", 15), command=self.register_user).place(x=550,
y=400)
Button(self.register_screen, text="返回首页", width=10, font=("宋体", 15), command=self.Destroy).place(x=750, y=400)
self.register_screen.mainloop()
def AdLogin(self):
self.cheek_username = StringVar()
self.main_screen.destroy()
self.admin_screen = Tk()
self.admin_screen.geometry("1442x700")
self.admin_screen.title("查询界面")
self.bg = PhotoImage(file='background.png')
Label(self.admin_screen, image=self.bg).place(x=0, y=0)
Label(self.admin_screen, text="欢迎来到查询界面", font=("宋体", 20)).place(x=600, y=30)
Label(self.admin_screen, font=("宋体", 15), text="账号").place(x=500, y=100)
self.username3 = Entry(self.admin_screen, textvariable=self.cheek_username, width=40, font=("宋体", 15))
self.username3.place(x=550, y=100)
self.columns = ("序号", "得分", "时间", "序号1", "得分1", "时间1", "序号2", "得分2", "时间2")
self.tree = ttk.Treeview(self.admin_screen, height=20, show="headings", columns=self.columns) # 隐藏首列
self.tree.column("序号", width=60) # 表示列,不显示
self.tree.column("得分", width=170) # 表示列,不显示
self.tree.column("时间", width=170) # 表示列,不显示
self.tree.column("序号1", width=60) # 表示列,不显示
self.tree.column("得分1", width=170) # 表示列,不显示
self.tree.column("时间1", width=170) # 表示列,不显示
self.tree.column("序号2", width=60) # 表示列,不显示
self.tree.column("得分2", width=170) # 表示列,不显示
self.tree.column("时间2", width=170) # 表示列,不显示
self.tree.place(x=130, y=150)
Button(self.admin_screen, text="查询", width=10, font=("宋体", 15), command=self.serach).place(x=200, y=600)
Button(self.admin_screen, text="查询所有玩家最高分", width=20, font=("宋体", 15), command=self.serach_best).place(x=620,
y=600)
Button(self.admin_screen, text="返回首页", width=10, font=("宋体", 15), command=self.Destroy1).place(x=1120, y=600)
self.admin_screen.mainloop()
def serach(self):
x = self.tree.get_children()
for item in x:
self.tree.delete(item)
conn = pymysql.connect(host='localhost', user='root', passwd='123456', db='testdb', port=3306,
charset='utf8')
cur = conn.cursor()
select_sql = "select un from user WHERE un=%s"
cur.execute(select_sql, [self.username3.get()])
result = cur.fetchone()
if len(self.username3.get()) == 0:
messagebox.showinfo("错误", "请输入账号!")
cur.close()
conn.close()
elif result is None:
messagebox.showinfo("错误", "该账号不存在!")
cur.close()
conn.close()
else:
self.tree.heading("序号", text='序号', anchor=CENTER)
self.tree.heading("得分", text='得分', anchor=CENTER)
self.tree.heading("时间", text='时间', anchor=CENTER)
self.tree.heading("序号1", text='序号', anchor=CENTER)
self.tree.heading("得分1", text='得分', anchor=CENTER)
self.tree.heading("时间1", text='时间', anchor=CENTER)
self.tree.heading("序号2", text='序号', anchor=CENTER)
self.tree.heading("得分2", text='得分', anchor=CENTER)
self.tree.heading("时间2", text='时间', anchor=CENTER)
select_sql = "select id from user WHERE un=%s"
cur.execute(select_sql, [self.username3.get()])
select_sql = "select code, time from code_lable WHERE userid=%s"
cur.execute(select_sql, [cur.fetchone()[0]])
lists = cur.fetchall()
lists = list(lists)
lists = list(reversed(lists))
print(len(lists))
if len(lists) == 0:
self.tree.insert("", 0, values=(1, '暂无数据'))
elif len(lists) > 0 and len(lists) <= 20:
for i in range(0, len(lists)):
self.tree.insert("", i, values=(i + 1, lists[i][0], lists[i][1]))
elif len(lists) > 20 and len(lists) <= 40:
for i in range(0, len(lists) - 20):
self.tree.insert("", i, values=(
i + 1, lists[i][0], lists[i][1], i + 21, lists[i + 20][0], lists[i + 20][1]))
for x in range(i + 1, 21):
self.tree.insert("", x, values=(x + 1, lists[x][0], lists[x][1]))
elif len(lists) > 40 and len(lists) <= 60:
for i in range(0, len(lists) - 40):
self.tree.insert("", i, values=(
i + 1, lists[i][0], lists[i][1], i + 21, lists[i + 20][0], lists[i + 20][1], i + 41,
lists[i + 40][0], lists[i + 40][1]))
for x in range(i + 1, 21):
self.tree.insert("", x, values=(
x + 1, lists[x][0], lists[x][1], x + 21, lists[x + 20][0], lists[x + 20][1]))
else:
for i in range(20):
self.tree.insert("", i, values=(
i + 1, lists[i][0], lists[i][1], i + 21, lists[i + 20][0], lists[i + 20][1], i + 41,
lists[i + 40][0], lists[i + 40][1]))
cur.close()
conn.close()
def serach_best(self):
self.tree.heading("序号", text='玩家ID', anchor=CENTER)
self.tree.heading("得分", text='最高得分', anchor=CENTER)
self.tree.heading("时间", text='时间', anchor=CENTER)
self.tree.heading("序号1", text='玩家ID', anchor=CENTER)
self.tree.heading("得分1", text='最高得分', anchor=CENTER)
self.tree.heading("时间1", text='时间', anchor=CENTER)
self.tree.heading("序号2", text='玩家ID', anchor=CENTER)
self.tree.heading("得分2", text='最高得分', anchor=CENTER)
self.tree.heading("时间2", text='时间', anchor=CENTER)
x = self.tree.get_children()
for item in x:
self.tree.delete(item)
self.username3.delete(0, END)
conn = pymysql.connect(host='localhost', user='root', passwd='123456', db='testdb', port=3306,
charset='utf8')
cur = conn.cursor()
select_sql = "select un from user"
cur.execute(select_sql)
result = cur.fetchall()
datas = []
for i in range(0, len(result)):
ID = result[i]
select_sql = "select id from user WHERE un=%s"
cur.execute(select_sql, [ID[0]])
id = cur.fetchone()
select_sql = "select code, time from code_lable WHERE userid=%s"
cur.execute(select_sql, [id[0]])
data = cur.fetchall()
max_list = []
data_list = []
for x in data:
max_list.append(int(x[0]))
print(max_list)
if len(max_list) > 0:
data_list.append(ID[0])
data_list.append(max(max_list))
data_list.append(data[max_list.index(max(max_list))][1])
else:
data_list.append(ID[0])
data_list.append('暂无数据')
datas.append(data_list)
# print(datas)
if len(datas) == 0:
messagebox.showinfo("错误", "暂无注册用户!")
cur.close()
conn.close()
elif len(datas) > 0 and len(datas) <= 20:
for i in range(len(datas)):
if len(datas[i]) == 2:
self.tree.insert("", i, values=(datas[i][0], datas[i][1]))
else:
self.tree.insert("", i, values=(datas[i][0], datas[i][1], datas[i][2]))
elif len(datas) > 20 and len(datas) <= 40:
for i in range(len(datas) - 20):
if len(datas[i]) == 2 and len(datas[i + 20]) == 2:
self.tree.insert("", i, values=(datas[i][0], datas[i][1], '', datas[i + 20][0], datas[i + 20][1]))
elif len(datas[i]) == 2 and len(datas[i + 20]) == 3:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], '', datas[i + 20][0], datas[i + 20][1], datas[i + 20][2]))
elif len(datas[i]) == 3 and len(datas[i + 20]) == 3:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], datas[i][2], datas[i + 20][0], datas[i + 20][1], datas[i + 20][2]))
elif len(datas[i]) == 3 and len(datas[i + 20]) == 2:
self.tree.insert("", i,
values=(datas[i][0], datas[i][1], datas[i][2], datas[i + 20][0], datas[i + 20][1]))
for x in range(i + 1, 21):
if len(datas[x]) == 2:
self.tree.insert("", x, values=(datas[x][0], datas[x][1]))
else:
self.tree.insert("", x, values=(datas[x][0], datas[x][1], datas[x][2]))
elif len(datas) > 40 and len(datas) <= 60:
for i in range(len(datas) - 40):
if len(datas[i]) == 2 and len(datas[i + 20]) == 2 and len(datas[i + 40]) == 2:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], '', datas[i + 20][0], datas[i + 20][1], '', datas[i + 40][0],
datas[i + 40][1]))
elif len(datas[i]) == 2 and len(datas[i + 20]) == 2 and len(datas[i + 40]) == 3:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], '', datas[i + 20][0], datas[i + 20][1], '', datas[i + 40][0],
datas[i + 40][1], datas[i + 40][2]))
elif len(datas[i]) == 2 and len(datas[i + 20]) == 3 and len(datas[i + 40]) == 2:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], '', datas[i + 20][0], datas[i + 20][1], datas[i + 20][2],
datas[i + 40][0], datas[i + 40][1]))
elif len(datas[i]) == 3 and len(datas[i + 20]) == 2 and len(datas[i + 40]) == 2:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], datas[i][2], datas[i + 20][0], datas[i + 20][1], '', datas[i + 40][0],
datas[i + 40][1]))
elif len(datas[i]) == 3 and len(datas[i + 20]) == 3 and len(datas[i + 40]) == 2:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], datas[i][2], datas[i + 20][0], datas[i + 20][1], datas[i + 20][2],
datas[i + 40][0], datas[i + 40][1]))
elif len(datas[i]) == 3 and len(datas[i + 20]) == 2 and len(datas[i + 40]) == 3:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], datas[i][2], datas[i + 20][0], datas[i + 20][1], '', datas[i + 40][0],
datas[i + 40][1], datas[i + 40][2]))
elif len(datas[i]) == 2 and len(datas[i + 20]) == 3 and len(datas[i + 40]) == 3:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], '', datas[i + 20][0], datas[i + 20][1], datas[i + 20][2],
datas[i + 40][0], datas[i + 40][1], datas[i + 40][2]))
elif len(datas[i]) == 3 and len(datas[i + 20]) == 3 and len(datas[i + 40]) == 3:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], datas[i][2], datas[i + 20][0], datas[i + 20][1], datas[i + 20][2],
datas[i + 40][0], datas[i + 40][1], datas[i + 40][2]))
for x in range(i + 1, 21):
if len(datas[x]) == 2 and len(datas[x + 20]) == 2:
self.tree.insert("", x, values=(datas[x][0], datas[x][1], '', datas[x + 20][0], datas[x + 20][1]))
elif len(datas[x]) == 2 and len(datas[x + 20]) == 3:
self.tree.insert("", x, values=(
datas[x][0], datas[x][1], '', datas[x + 20][0], datas[x + 20][1], datas[x + 20][2]))
elif len(datas[x]) == 3 and len(datas[x + 20]) == 3:
self.tree.insert("", x, values=(
datas[x][0], datas[x][1], datas[x][2], datas[x + 20][0], datas[x + 20][1], datas[x + 20][2]))
elif len(datas[x]) == 3 and len(datas[x + 20]) == 2:
self.tree.insert("", x,
values=(datas[x][0], datas[x][1], datas[x][2], datas[x + 20][0], datas[x + 20][1]))
else:
for i in range(20):
if len(datas[i]) == 2 and len(datas[i + 20]) == 2 and len(datas[i + 40]) == 2:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], '', datas[i + 20][0], datas[i + 20][1], '', datas[i + 40][0],
datas[i + 40][1]))
elif len(datas[i]) == 2 and len(datas[i + 20]) == 2 and len(datas[i + 40]) == 3:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], '', datas[i + 20][0], datas[i + 20][1], '', datas[i + 40][0],
datas[i + 40][1], datas[i + 40][2]))
elif len(datas[i]) == 2 and len(datas[i + 20]) == 3 and len(datas[i + 40]) == 2:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], '', datas[i + 20][0], datas[i + 20][1], datas[i + 20][2],
datas[i + 40][0], datas[i + 40][1]))
elif len(datas[i]) == 3 and len(datas[i + 20]) == 2 and len(datas[i + 40]) == 2:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], datas[i][2], datas[i + 20][0], datas[i + 20][1], '', datas[i + 40][0],
datas[i + 40][1]))
elif len(datas[i]) == 3 and len(datas[i + 20]) == 3 and len(datas[i + 40]) == 2:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], datas[i][2], datas[i + 20][0], datas[i + 20][1], datas[i + 20][2],
datas[i + 40][0], datas[i + 40][1]))
elif len(datas[i]) == 3 and len(datas[i + 20]) == 2 and len(datas[i + 40]) == 3:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], datas[i][2], datas[i + 20][0], datas[i + 20][1], '', datas[i + 40][0],
datas[i + 40][1], datas[i + 40][2]))
elif len(datas[i]) == 2 and len(datas[i + 20]) == 3 and len(datas[i + 40]) == 3:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], '', datas[i + 20][0], datas[i + 20][1], datas[i + 20][2],
datas[i + 40][0], datas[i + 40][1], datas[i + 40][2]))
elif len(datas[i]) == 3 and len(datas[i + 20]) == 3 and len(datas[i + 40]) == 3:
self.tree.insert("", i, values=(
datas[i][0], datas[i][1], datas[i][2], datas[i + 20][0], datas[i + 20][1], datas[i + 20][2],
datas[i + 40][0], datas[i + 40][1], datas[i + 40][2]))
cur.close()
conn.close()
def Admin_login_verify(self):
self.username2 = self.username_verify.get()
self.password2 = self.password_verify.get()
conn = pymysql.connect(host='localhost', user='root', passwd='123456', db='testdb', port=3306,
charset='utf8')
cur = conn.cursor()
select_sql = "select passward from admin WHERE username=%s"
cur.execute(select_sql, [self.username2])
result = cur.fetchone()
if len(self.username2) == 0:
messagebox.showinfo("错误", "请输入账号!")
cur.close()
conn.close()
elif result is None:
cur.close()
conn.close()
messagebox.showinfo("失败", "该账号未注册!")
self.password_login_entry.delete(0, END)
self.username_login_entry.delete(0, END)
else:
if result[0] == self.password2:
cur.close()
conn.close()
messagebox.showinfo("成功", "登录成功")
self.username_login_entry.delete(0, END)
self.password_login_entry.delete(0, END)
self.AdLogin()
elif result[0] != self.password2:
cur.close()
conn.close()
messagebox.showinfo("失败", "密码错误!")
self.password_login_entry.delete(0, END)
def Destroy(self):
self.register_screen.destroy()
gui_start().set_init_window()
def Destroy1(self):
self.admin_screen.destroy()
gui_start().set_init_window()
def Destroy2(self):
self.user_screen1.destroy()
gui_start().set_init_window()
def Destroy3(self):
self.user_screen1.destroy()
go(self.username1)
def gui_start():
init_window = Tk() # 实例化出一个父窗口
return My_Gui(init_window)
# 设置根窗口默认属性
# ZMJ_PORTAL.set_init_window()
# init_window.mainloop() # 父窗口进入事件循环,可以理解为保持窗口运行,否则界面不展示
# if __name__ == '__main__':
# gui_start().set_init_window()
总结
这就是我自己写的基于python和mysql的飞机大战小游戏,由于代码太长,篇幅有限,如果有需要源码的小伙伴们可以来qq加我:3090677003.(第一次写博客还希望大家点赞,谢谢!!(●'?'●))
|