用wxpython 编写一个登录界面

时间: 2023-09-13 12:11:22 浏览: 50
好的,我可以给你提供一个简单的登录界面的代码示例: ``` import wx class LoginFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "登录界面", size=(300, 200)) self.panel = wx.Panel(self, -1) self.label_user = wx.StaticText(self.panel, -1, "用户名:", pos=(50, 50)) self.text_user = wx.TextCtrl(self.panel, -1, "", size=(150, -1), pos=(110, 50)) self.label_pwd = wx.StaticText(self.panel, -1, "密码:", pos=(50, 90)) self.text_pwd = wx.TextCtrl(self.panel, -1, "", size=(150, -1), pos=(110, 90), style=wx.TE_PASSWORD) self.button_login = wx.Button(self.panel, -1, "登录", pos=(110, 130)) self.button_login.Bind(wx.EVT_BUTTON, self.on_login) self.Bind(wx.EVT_CLOSE, self.on_close) def on_login(self, event): user = self.text_user.GetValue() pwd = self.text_pwd.GetValue() if user == "admin" and pwd == "123": wx.MessageBox("登录成功!", "提示", wx.OK | wx.ICON_INFORMATION, self) else: wx.MessageBox("用户名或密码错误!", "提示", wx.OK | wx.ICON_ERROR, self) def on_close(self, event): self.Destroy() if __name__ == "__main__": app = wx.App() frame = LoginFrame() frame.Show() app.MainLoop() ``` 这是一个基于wxPython库编写的登录界面,包括用户名、密码的输入框以及登录按钮。用户输入用户名和密码后点击登录按钮,程序会判断是否正确,如果正确,则弹出登录成功的提示框,否则弹出用户名或密码错误的提示框。您可以根据自己的需要进行修改和补充,比如加入记住密码功能、忘记密码链接等。

相关推荐

txt
/MainFrame.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MainFrame extends JFrame implements ActionListener{ private Container cont; private JPanel panelMenu; private JPanel panelToolBar; private JPanel panelCompent; private JButton btnLeft; private JButton btnCenter; private JButton btnRight; private JButton btnBorder; private JButton btnGrid; private JLabel labHit; private JMenuBar menuBar; private JMenu menuOperation; private JMenu menuHelp; private JMenuItem mItemFlowLeft; private JMenuItem mItemFlowCenter; private JMenuItem mItemFlowRight; private JMenuItem mItemBorder; private JMenuItem mItemGrid; private JToolBar toolBar; private JButton tBtnLeft; private JButton tBtnCenter; private JButton tBtnRight; private JButton tBtnBorder; private JButton tBtnGrid; public MainFrame(){ this.setTitle("第一个界面"); this.setBounds(300, 300, 600, 450); this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); cont = this.getContentPane(); // cont.setLayout(new GridLayout(3, 9)); cont.setLayout(null); initPanel(); initMenu(); initToolBar(); initCompent(); addMenu(); addCompent(); // addBorderCompent(); this.setVisible(true); } public void initPanel(){ panelMenu = new JPanel(); panelMenu.setLayout(new FlowLayout(FlowLayout.LEFT)); panelMenu.setBounds(0, 0, 600, 30); panelToolBar = new JPanel(); panelToolBar.setLayout(new FlowLayout(FlowLayout.LEFT)); panelToolBar.setBounds(0, 30, 600, 50); panelCompent = new JPanel(); panelCompent.setLayout(new GridLayout(3, 2)); panelCompent.setBounds(0, 80, 600, 350); cont.add(panelMenu); cont.add(panelToolBar); cont.add(panelCompent); } public void initMenu(){ menuBar = new JMenuBar(); menuOperation = new JMenu("布局操作"); menuHelp = new JMenu("帮助"); mItemFlowLeft = new JMenuItem("流式左布局"); mItemFlowLeft.addActionListener(this); mItemFlowCenter = new JMenuItem("流式居中"); mItemFlowCenter.addActionListener(this); mItemFlowRight = new JMenuItem("流式右布局"); mItemFlowRight.addActionListener(this); mItemBorder = new JMenuItem("边界布局"); mItemBorder.addActionListener(this); mItemGrid = new JMenuItem("网格布局"); mItemGrid.addActionListener(this); } public void initToolBar(){ toolBar = new JToolBar(); tBtnLeft = new JButton(new ImageIcon("COPY.jpg")); tBtnLeft.addActionListener(this); tBtnLeft.setToolTipText("流式左布局"); tBtnCenter = new JButton(new ImageIcon("HELP.jpg")); tBtnCenter.addActionListener(this); tBtnCenter.setToolTipText("流式居中"); tBtnRight = new JButton(new ImageIcon("find.jpg")); tBtnRight.addActionListener(this); tBtnRight.setToolTipText("流式右布局"); tBtnBorder = new JButton(new ImageIcon("CUT.jpg")); tBtnBorder.addActionListener(this); tBtnBorder.setToolTipText("边界布局"); tBtnGrid = new JButton(new ImageIcon("OPEN.jpg")); tBtnGrid.addActionListener(this); tBtnGrid.setToolTipText("网格布局"); toolBar.add(tBtnLeft); toolBar.add(tBtnCenter); toolBar.add(tBtnRight); toolBar.add(tBtnBorder); toolBar.add(tBtnGrid); panelToolBar.add(toolBar); } public void initCompent(){ btnLeft = new JButton("LEFT"); btnLeft.addActionListener(this); btnRight = new JButton("RIGHT"); btnRight.addActionListener(this); btnCenter = new JButton("CENTER"); btnCenter.addActionListener(this); btnBorder = new JButton("BORDER"); btnBorder.addActionListener(this); btnGrid = new JButton("GRID"); btnGrid.addActionListener(this); labHit = new JLabel("提示"); } public void addMenu(){ menuOperation.add(mItemFlowLeft); menuOperation.add(mItemFlowCenter); menuOperation.add(mItemFlowRight); menuOperation.add(mItemBorder); menuOperation.add(mItemGrid); menuBar.add(menuOperation); menuBar.add(menuHelp); panelMenu.add(menuBar); } public void addCompent(){ panelCompent.add(btnLeft); panelCompent.add(btnCenter); panelCompent.add(btnRight); panelCompent.add(btnBorder); panelCompent.add(btnGrid); panelCompent.add(labHit); } public void addBorderCompent(){ panelCompent.add(btnLeft, "West"); panelCompent.add(btnCenter, "Center"); panelCompent.add(btnRight, "East"); panelCompent.add(btnBorder, "North"); panelCompent.add(btnGrid, "South"); } public void actionPerformed(ActionEvent aEvt){ if((btnLeft == aEvt.getSource()) ||(mItemFlowLeft == aEvt.getSource()) ||(tBtnLeft == aEvt.getSource())){ panelCompent.setLayout(new FlowLayout(FlowLayout.LEFT)); labHit.setText("流式布局管理器左靠齐"); } else { if((btnRight == aEvt.getSource()) ||(mItemFlowRight == aEvt.getSource()) ||(tBtnRight == aEvt.getSource())){ panelCompent.setLayout(new FlowLayout(FlowLayout.RIGHT)); labHit.setText("流式布局管理器右靠齐"); } else { if((btnCenter == aEvt.getSource()) ||(mItemFlowCenter == aEvt.getSource()) ||(tBtnCenter == aEvt.getSource())){ panelCompent.setLayout(new FlowLayout(FlowLayout.CENTER)); labHit.setText("流式布局管理器中靠齐"); } else { if((btnBorder == aEvt.getSource()) ||(mItemBorder == aEvt.getSource()) ||(tBtnBorder == aEvt.getSource())){ panelCompent.setLayout(new BorderLayout()); addBorderCompent(); labHit.setText("边界布局管理器"); } else{ if((btnGrid == aEvt.getSource()) ||(mItemGrid == aEvt.getSource()) ||(tBtnGrid == aEvt.getSource()) ){ panelCompent.setLayout(new GridLayout(3, 2)); // addBorderCompent(); labHit.setText("网格布局管理器"); } } } } } } } //LoginFrame.java import javax.swing.*; import java.awt.*; import java.awt.event.*; class LoginFrame extends JFrame implements ActionListener{ private Container cont; private JLabel labUserName; private JLabel labPassword; private JTextField txtUserName; private JTextField txtPassword; private JButton btnOK; private JButton btnCancel; public LoginFrame(){ this.setTitle("登录界面"); this.setSize(300, 250); this.setLocation(300, 300); this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); initCont(); initCompent(); addCompent(); this.setVisible(true); } public void initCont(){ cont = this.getContentPane(); cont.setLayout(null); } public void initCompent(){ labUserName = new JLabel("用户名:"); labPassword = new JLabel("密 码:"); txtUserName = new JTextField(); txtPassword = new JPasswordField(); btnOK = new JButton("登录"); btnCancel = new JButton("重置"); } public void addCompent(){ cont.add(labUserName); labUserName.setBounds(40,40,80,30); cont.add(labPassword); labPassword.setBounds(40,90,80,30); cont.add(txtUserName); txtUserName.setBounds(120,40,120,30); cont.add(txtPassword); txtPassword.setBounds(120,90,120,30); cont.add(btnOK); btnOK.addActionListener(this); btnOK.setBounds(60,170,80,30); cont.add(btnCancel); btnCancel.addActionListener(this); btnCancel.setBounds(160,170,80,30); } public void actionPerformed(ActionEvent aEvt){ if(aEvt.getSource() == btnOK){ if((txtUserName.getText().equals("denghong")) &&(txtPassword.getText().equals("123"))){ new MainFrame(); this.dispose(); } } else{ if(aEvt.getSource() == btnCancel){ labUserName.setText(""); labPassword.setText(""); } } } } //Test.java public class Test{ public static void main(String[] args){ new LoginFrame(); } }

最新推荐

recommend-type

wxpython实现按钮切换界面的方法

在Python的GUI编程中,wxPython库是一个常用的选择,它提供了丰富的控件和功能来构建桌面应用程序。本篇文章将详细介绍如何使用wxPython实现按钮切换界面的功能。首先,我们需要了解wxPython的基础知识,它是Python...
recommend-type

WxPython实现无边框界面

在Python的GUI编程中,WxPython库是一个广泛使用的工具,它提供了丰富的控件和功能,使得开发者能够方便地创建出美观且功能完备的图形用户界面。无边框界面是一种特殊的界面设计,它去掉了窗口的常规边框,通常用于...
recommend-type

python wxpython 实现界面跳转功能

在Python编程中,创建图形用户界面(GUI)时,wxPython是一个广泛使用的库。然而,wxPython本身并没有提供直接的界面跳转功能。在这种情况下,开发者需要利用其他技术来实现这一需求,如使用多线程(threading)模块...
recommend-type

wxpython+pymysql实现用户登陆功能

3. **用户登录功能实现**:在描述中,我们看到使用wxPython和PyMySQL来创建一个简单的用户登录界面。首先,设计了一个窗口界面,包括登录和注册按钮,以及可能需要的输入字段,如用户名和密码。当用户点击登录按钮时...
recommend-type

python图形界面开发之wxPython树控件使用方法详解

树(tree)是一种通过层次结构展示信息的控件,如下图所示是树控件示例,左窗口中是树控件,在wxPython中树控件类是wx.TreeCtrl。 wx.TreeCtrl常用的方法有 AddRoot(text, image=-1, selImage=-1, data=None)。...
recommend-type

汽车传感器详解:超声波检测涡流式空气流量传感器

"本文主要介绍了汽车传感器的各种类型和其中的超声波检测涡流式空气流量传感器的工作原理及电路。汽车传感器包括温度传感器、空气流量传感器、压力传感器、位置与角度传感器、速度与加速度传感器、振动传感器以及气体浓度传感器等,每个类型的传感器都在汽车的不同系统中起到关键的作用。" 在汽车工程中,传感器扮演着至关重要的角色,它们负责收集各种物理和化学信号,以确保引擎和其他系统的高效运行。超声波检测涡流式空气流量传感器是其中的一种,它通过检测空气流经传感器时产生的涡流来精确测量进入发动机的空气质量。这种技术提供了更准确的数据,有助于优化燃油喷射和点火正时,从而提高发动机性能和燃油效率。 温度传感器是汽车中最常见的传感器之一,包括水温传感器、空气温度传感器等,它们用于监控发动机及其周围环境的温度状态,以确保引擎在适宜的温度下运行并防止过热。例如,水温传感器检测发动机冷却水的温度,其信号用于调整燃油混合比和点火提前角。 空气流量传感器有多种类型,如翼片式、卡门涡旋式(包括超声波式)、热线式和热膜式。这些传感器的主要任务是测量进入发动机的空气流量,以便控制燃油喷射量,保证燃烧的充分。超声波式空气流量传感器利用超声波频率的变化来确定空气流动的速度,从而计算流量。 压力传感器则用于监测进气歧管压力、大气压力以及各种液体的压力,例如机油、刹车液、空调系统压力等,以确保系统正常运行并预防故障。 位置与角度传感器,如节气门位置传感器和转向角度传感器,提供关于发动机工况和车辆方向的关键信息。速度与加速度传感器,如曲轴位置传感器和车速传感器,帮助确定发动机的工作周期和车辆的行驶速度,对于发动机管理和防抱死刹车系统(ABS)至关重要。 振动传感器,如碰撞传感器和爆震传感器,用于检测车辆的振动和冲击,确保安全系统如安全气囊和发动机管理系统能在必要时做出反应。 气体浓度传感器,如氧传感器和烟雾浓度传感器,监测尾气中的氧气和有害物质含量,以调整空燃比,降低排放,并提高燃油经济性。 学习传感器的知识,不仅要知道它们的作用、安装位置,还要了解其结构、工作原理、电路图,以及如何进行静态和动态检测,包括电阻测量、电源电压检测和信号电压测量,甚至进行波形分析,这些都是汽车维修和诊断的重要技能。例如,水温传感器在不同温度下的电阻值是检测其是否正常工作的依据,如桑塔纳2000GSi轿车的水温传感器在0℃时电阻为6kΩ,随着温度升高,电阻逐渐减小。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

SVM分类算法与其他分类算法的巅峰对决:谁是分类之王?

![SVM分类算法与其他分类算法的巅峰对决:谁是分类之王?](https://img-blog.csdnimg.cn/img_convert/b9aa536ef68773bf76dd670866205601.png) # 1. 分类算法概述 分类算法是机器学习中用于将数据点分配到预定义类别的技术。它们广泛应用于各种领域,包括模式识别、自然语言处理和金融预测。分类算法有多种类型,每种算法都有其独特的优势和劣势。 在本章中,我们将讨论分类算法的基本原理,包括监督学习、特征选择和模型评估。我们将介绍各种常见的分类算法,例如支持向量机(SVM)、决策树和朴素贝叶斯。我们将探讨这些算法的优点和缺点,
recommend-type

obsidian的ios

Obsidian是一款非常受欢迎的基于Markdown的笔记应用,它最初是为Windows和Mac设计的,后来也推出了iOS版本。在iOS上,Obsidian为用户提供了跨平台的同步功能,允许你在iPhone、iPad等设备上方便地编辑和管理你的知识库。Obsidian iOS版支持离线查看、实时预览、丰富的插件系统以及强大的组织架构,包括网络、笔记本、文件夹和卡片等,让你能够创建深度链接和思维导图,打造个人的知识管理体系。 该应用的特点在于其支持自动化脚本(Zettelkasten实践)、内嵌Git版本控制,以及与其他Obsidian用户的协作工具。不过,由于Obsidian在移动设备上可
recommend-type

汽车传感器详解:类型、应用与检测要点

本文档主要介绍了汽车传感器技术的基础知识,涵盖了多种类型的传感器及其在汽车系统中的应用。以下是对各部分知识点的详细解析: 1. **传感器类型** - **温度传感器**:包括水温传感器、空气温度传感器、变速器油温传感器、排放温度传感器(催化剂温度传感器)、EGR监测温度传感器、车外温度传感器、车内温度传感器、日照温度传感器、蒸发器出口温度传感器以及电池温度传感器和热敏开关。 - **空气流量传感器**:有翼片式(叶片式)、卡门涡旋式(光电式和超声波式)、热线式和热膜式等类型。 - **压力传感器**:涉及进气管压力传感器、大气压力传感器、空气滤清器真空开关、机油压力开关、空调压力开关、制动系统油压传感器、主动悬架系统压力传感器、制动主缸油压传感器、蓄压器压力传感器和增压传感器。 - **位置与角度传感器**:如节气门位置传感器、转向角度传感器、光电式车高传感器和液位传感器。 - **速度与加速度传感器**:包括曲轴位置(转速)传感器(磁脉冲式、霍尔式或光电式)、上止点位置传感器、缸位判别传感器、车速传感器、输入轴转速传感器和轮速传感器,以及ABS加速度传感器。 - **振动传感器**:用于碰撞检测和爆震监测。 - **气体浓度传感器**:氧传感器(二氧化锆式和二氧化钛式)、稀薄混合气传感器和烟雾浓度传感器。 2. **学习传感器的知识要点** - **作用**:汽车传感器的核心功能是监测并测量各种物理参数,如温度、流量、压力、位置、速度、加速度等,以便于车辆控制系统进行精确的控制。 - **安装位置**:每种传感器通常被安装在对应系统的关键部位,如发动机冷却系统、进气道、刹车系统等。 - **结构**:涉及传感器的物理设计,如机械、电子元件的组合。 - **工作原理**:详细解释了传感器如何将物理信号转化为电信号的过程。 - **电路图**:展示了传感器在车辆电气系统中的连接方式和信号传输路径。 - **静态检测与动态检测**:介绍如何通过电阻、导通性、电源电压和信号电压等参数来检查传感器的工作状态。 - **波形分析**:对于某些类型的传感器,了解其输出信号的波形有助于理解其性能和故障诊断。 在学习和维护汽车传感器时,理解这些关键知识点至关重要,它们能够帮助我们更好地理解和维护车辆的电子系统,确保其正常运行和优化性能。