写好了登录和切换
This commit is contained in:
parent
90e5cb15e5
commit
534e2b2892
154
python/test/Cilent/Login.py
Normal file
154
python/test/Cilent/Login.py
Normal file
@ -0,0 +1,154 @@
|
||||
import wx
|
||||
import threading
|
||||
|
||||
|
||||
class LoginFrame(wx.Frame):
|
||||
def __init__(self):
|
||||
wx.Frame.__init__(self, None, id=1001, title='登录', pos=wx.DefaultPosition, size=(400, 300))
|
||||
|
||||
# 创建菜单栏
|
||||
menu_bar = wx.MenuBar()
|
||||
|
||||
# 登录菜单
|
||||
login_menu = wx.Menu()
|
||||
menu_bar.Append(login_menu, "登录")
|
||||
|
||||
# 更多菜单
|
||||
more_menu = wx.Menu()
|
||||
self.register_id = wx.NewId()
|
||||
self.retrieve_id = wx.NewId()
|
||||
self.set_server_id = wx.NewId()
|
||||
more_menu.Append(self.register_id, "注册账号")
|
||||
more_menu.Append(self.retrieve_id, "找回密码")
|
||||
more_menu.Append(self.set_server_id, "服务器设置")
|
||||
menu_bar.Append(more_menu, "更多")
|
||||
|
||||
self.SetMenuBar(menu_bar)
|
||||
|
||||
# 创建状态栏
|
||||
self.status_bar = self.CreateStatusBar(4)
|
||||
self.status_bar.SetStatusText("服务器连接:", 0)
|
||||
self.status_bar.SetStatusText("状态:", 2)
|
||||
|
||||
# 获取菜单点击事件
|
||||
self.Bind(wx.EVT_MENU, self.click_menu, id=self.register_id)
|
||||
self.Bind(wx.EVT_MENU, self.click_menu, id=self.retrieve_id)
|
||||
self.Bind(wx.EVT_MENU, self.click_menu, id=self.set_server_id)
|
||||
self.Bind(wx.EVT_MENU_OPEN, self.click_menu_title)
|
||||
|
||||
# 创建注册面板
|
||||
self.panel = RegisterPanel(self)
|
||||
self.panel.Show()
|
||||
|
||||
def click_menu_title(self, event):
|
||||
menu = event.GetMenu()
|
||||
menu_title = menu.GetTitle()
|
||||
if menu_title == "登录":
|
||||
self.panel.Destroy()
|
||||
self.panel = LoginPanel(self)
|
||||
self.panel.Show()
|
||||
self.Layout()
|
||||
|
||||
|
||||
|
||||
# 点击菜单检测
|
||||
def click_menu(self, event):
|
||||
menu_id = event.GetId()
|
||||
if menu_id == self.register_id:
|
||||
self.panel.Destroy()
|
||||
self.panel = RegisterPanel(self)
|
||||
self.panel.Show()
|
||||
self.Layout()
|
||||
elif menu_id == self.retrieve_id:
|
||||
self.panel.Destroy()
|
||||
self.panel = LoginPanel(self)
|
||||
self.panel.Show()
|
||||
self.Layout()
|
||||
elif menu_id == self.set_server_id:
|
||||
self.panel.Destroy()
|
||||
self.panel = LoginPanel(self)
|
||||
self.panel.Show()
|
||||
self.Layout()
|
||||
|
||||
|
||||
class LoginPanel(wx.Panel):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
# 主盒子
|
||||
main_box = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
# 顶部盒子,目前只放了软件名
|
||||
top_box = wx.BoxSizer(wx.VERTICAL) # 使用垂直盒子
|
||||
show_title = wx.StaticText(self, label='Lsy chat')
|
||||
show_title.SetFont(wx.Font(30, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
|
||||
top_box.Add(show_title, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 10)
|
||||
main_box.Add(top_box, 0, wx.EXPAND)
|
||||
|
||||
# 中部盒子,放账号和密码
|
||||
content_box = wx.BoxSizer(wx.VERTICAL)
|
||||
# 账号
|
||||
account_box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
account_label = wx.StaticText(self, label=' 账号:')
|
||||
account_label.SetFont(wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
|
||||
account_box.Add(account_label, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
account_text = wx.TextCtrl(self, size=(300, 30))
|
||||
account_text.SetHint('请输入账号')
|
||||
account_box.Add(account_text, 1, wx.ALIGN_CENTER_VERTICAL)
|
||||
content_box.Add(account_box)
|
||||
# 添加空白控件来增加间距
|
||||
content_box.Add(wx.StaticText(self, label=''), 0, wx.ALL, 5)
|
||||
# 密码
|
||||
password_box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
password_label = wx.StaticText(self, label=' 密码:')
|
||||
password_label.SetFont(wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
|
||||
password_box.Add(password_label, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
password_text = wx.TextCtrl(self, size=(300, 30))
|
||||
password_text.SetHint('请输入密码')
|
||||
password_box.Add(password_text, 1, wx.ALIGN_CENTER_VERTICAL)
|
||||
content_box.Add(password_box)
|
||||
main_box.Add(content_box, 0, wx.EXPAND)
|
||||
|
||||
# 底部盒子
|
||||
bottom_box = wx.BoxSizer(wx.VERTICAL)
|
||||
# 登录按钮
|
||||
login_box = wx.BoxSizer(wx.VERTICAL) # 使用垂直盒子布局
|
||||
login_label = wx.Button(self, size=(200, 50), label='登录')
|
||||
login_box.AddStretchSpacer() # 添加一个可伸缩的空间,将登录按钮推到垂直中间
|
||||
login_box.Add(login_label, 0, wx.ALIGN_CENTER_HORIZONTAL) # 将登录按钮添加到垂直盒子中
|
||||
login_box.AddStretchSpacer() # 再次添加一个可伸缩的空间,将登录按钮推到垂直中间
|
||||
bottom_box.Add(login_box, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL) # 将垂直盒子添加到底部盒子中,设置垂直和水平居中对齐
|
||||
main_box.Add(bottom_box, 1, wx.EXPAND) # 将底部盒子添加到主盒子中,使其填满剩余空间
|
||||
|
||||
self.SetSizer(main_box)
|
||||
|
||||
|
||||
class RegisterPanel(wx.Panel):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent)
|
||||
|
||||
main_box = wx.BoxSizer(wx.VERTICAL)
|
||||
# 内容盒子,放账号和密码
|
||||
content_box = wx.BoxSizer(wx.VERTICAL)
|
||||
# 账号
|
||||
account_box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
account_label = wx.StaticText(self, label=' 账号:')
|
||||
account_label.SetFont(wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
|
||||
account_box.Add(account_label, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
account_text = wx.TextCtrl(self, size=(300, 30))
|
||||
account_text.SetHint('请输入账号')
|
||||
account_box.Add(account_text, 1, wx.ALIGN_CENTER_VERTICAL)
|
||||
content_box.Add(account_box)
|
||||
# 添加空白控件来增加间距
|
||||
content_box.Add(wx.StaticText(self, label=''), 0, wx.ALL, 5)
|
||||
# 密码
|
||||
password_box = wx.BoxSizer(wx.HORIZONTAL)
|
||||
password_label = wx.StaticText(self, label=' 密码:')
|
||||
password_label.SetFont(wx.Font(15, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
|
||||
password_box.Add(password_label, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
password_text = wx.TextCtrl(self, size=(300, 30))
|
||||
password_text.SetHint('请输入密码')
|
||||
password_box.Add(password_text, 1, wx.ALIGN_CENTER_VERTICAL)
|
||||
content_box.Add(password_box)
|
||||
main_box.Add(content_box, 0, wx.EXPAND)
|
||||
|
||||
self.SetSizer(main_box)
|
1
python/test/Cilent/__init__.py
Normal file
1
python/test/Cilent/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .Login import *
|
BIN
python/test/Cilent/__pycache__/Login.cpython-312.pyc
Normal file
BIN
python/test/Cilent/__pycache__/Login.cpython-312.pyc
Normal file
Binary file not shown.
BIN
python/test/Cilent/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
python/test/Cilent/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
7
python/test/main.py
Normal file
7
python/test/main.py
Normal file
@ -0,0 +1,7 @@
|
||||
import wx
|
||||
from Cilent import LoginFrame
|
||||
if __name__ == '__main__':
|
||||
app = wx.App()
|
||||
frame = LoginFrame()
|
||||
frame.Show()
|
||||
app.MainLoop()
|
121
python/test/test.py
Normal file
121
python/test/test.py
Normal file
@ -0,0 +1,121 @@
|
||||
import wx,time
|
||||
ID_EXIT=200
|
||||
ID_ABOUT=201
|
||||
|
||||
class Frame(wx.Frame): #2 wx.Frame子类
|
||||
def __init__(self,parent = None,id = -1,title ='系统管理界面'):
|
||||
wx.Frame.__init__(self,parent,id,title,size=(900,600))
|
||||
self.panel_Celan1 = None
|
||||
self.panel_Celan2 = None
|
||||
self.panel_Celan3 = None
|
||||
self.panel_Celan1_1 =None
|
||||
self.setupStatusBar()
|
||||
self.InitCelan()
|
||||
self.InitButton()
|
||||
|
||||
|
||||
#初始化状态栏
|
||||
def setupStatusBar(self):
|
||||
# 状态栏
|
||||
sb = self.CreateStatusBar(2) # 2代表将状态栏分为两个
|
||||
self.SetStatusWidths([-1, -2]) # 比例为1:2
|
||||
self.SetStatusText("Ready", 0) # 0代表第一个栏,Ready为内容
|
||||
# timmer
|
||||
self.timer = wx.PyTimer(self.Notify)
|
||||
self.timer.Start(1000, wx.TIMER_CONTINUOUS)
|
||||
self.Notify()
|
||||
|
||||
# 实时显示时间
|
||||
def Notify(self):
|
||||
t = time.localtime(time.time())
|
||||
st = time.strftime('%Y-%m-%d %H:%M:%S', t)
|
||||
self.SetStatusText(st, 1) # 这里的1代表将时间放入状态栏的第二部分上
|
||||
|
||||
|
||||
# 初始化登陆
|
||||
def InitButton(self):
|
||||
self.panel_Celan1 = wx.Panel(self, pos=(400, 150), size=(300, 300))
|
||||
wx.StaticText(self.panel_Celan1,label="Username",pos=(20,20))
|
||||
wx.StaticText(self.panel_Celan1, label="Password", pos=(20, 50))
|
||||
self._username=wx.TextCtrl(self.panel_Celan1,pos=(110,15))
|
||||
self._passwd = wx.TextCtrl(self.panel_Celan1, pos=(110, 45),style=wx.TE_PASSWORD)
|
||||
|
||||
self._submit_btn=wx.Button(self.panel_Celan1,label=u'提交',pos=(100,100),size=(50,30))
|
||||
self.panel_Celan1.Bind(wx.EVT_BUTTON,self.Onclick,self._submit_btn)
|
||||
|
||||
|
||||
#处理登陆事件
|
||||
def Onclick(self,event):
|
||||
global denglu_flag
|
||||
if event.GetEventObject()==self._submit_btn:
|
||||
user = self.GetUsername()
|
||||
passwd = self.GetPasswd()
|
||||
print(user+":"+passwd)
|
||||
if(user == "wenli"and passwd == "123456"):
|
||||
denglu_flag=True
|
||||
self.panel_Celan1.Destroy()
|
||||
self.panel_Celan1_1 =wx.Panel(self, pos=(400, 150), size=(300, 300))
|
||||
wx.StaticText(self.panel_Celan1_1, label="欢迎登陆", pos=(130, 150))
|
||||
def GetUsername(self):
|
||||
return self._username.GetValue()
|
||||
|
||||
def GetPasswd(self):
|
||||
return self._passwd.GetValue()
|
||||
|
||||
|
||||
|
||||
#处理侧栏的点击事件
|
||||
def Onclick_Ce(self,event):
|
||||
global denglu_flag
|
||||
if event.GetEventObject() == self._caidan1:
|
||||
# 如果需要显示的地方存在其他面板,删除
|
||||
if self.panel_Celan2:
|
||||
self.panel_Celan2.Destroy()
|
||||
if self.panel_Celan3:
|
||||
self.panel_Celan3.Destroy()
|
||||
if not self.panel_Celan1 :
|
||||
if(denglu_flag == False):
|
||||
self.InitButton()
|
||||
else:
|
||||
if not self.panel_Celan1_1:
|
||||
self.panel_Celan1_1 = wx.Panel(self, pos=(400, 150), size=(300, 300))
|
||||
wx.StaticText(self.panel_Celan1_1, label="欢迎登陆", pos=(130, 150))
|
||||
|
||||
|
||||
if event.GetEventObject()==self._caidan2:
|
||||
# 如果需要显示的地方存在其他面板,删除
|
||||
if self.panel_Celan1:
|
||||
self.panel_Celan1.Destroy()
|
||||
if self.panel_Celan1_1:
|
||||
self.panel_Celan1_1.Destroy()
|
||||
if self.panel_Celan3:
|
||||
self.panel_Celan3.Destroy()
|
||||
if not self.panel_Celan2 :
|
||||
self.panel_Celan2 = wx.Panel(self, pos=(200, 0), size=(700, 700))
|
||||
|
||||
if event.GetEventObject() == self._caidan3:
|
||||
if self.panel_Celan1:
|
||||
self.panel_Celan1.Destroy()
|
||||
if self.panel_Celan1_1:
|
||||
self.panel_Celan1_1.Destroy()
|
||||
if self.panel_Celan2 :
|
||||
self.panel_Celan2.Destroy()
|
||||
if not self.panel_Celan3:
|
||||
self.panel_Celan3 = wx.Panel(self, pos=(400, 150), size=(300, 300))
|
||||
wx.StaticText(self.panel_Celan3, label="公告", pos=(130, 150))
|
||||
|
||||
|
||||
class App(wx.App): #5 wx.App子类
|
||||
def __init__(self):
|
||||
#如果要重写__init__,必须调用wx.App的__init__,否则OnInit方法不会被调用
|
||||
wx.App.__init__(self)
|
||||
def OnInit(self):
|
||||
self.frame=Frame()
|
||||
self.SetTopWindow(self.frame)
|
||||
self.frame.Show()
|
||||
|
||||
return True
|
||||
if __name__=="__main__":
|
||||
denglu_flag = False
|
||||
app = App()
|
||||
app.MainLoop()
|
Loading…
Reference in New Issue
Block a user