import wx import gui app = wx.App() win = gui.login(None) win.Show(True) app.MainLoop()
# -*- coding: utf-8 -*- ########################################################################### ## Python code generated with wxFormBuilder (version Feb 26 2014) ## http://www.wxformbuilder.org/ ## ## PLEASE DO "NOT" EDIT THIS FILE! ########################################################################### import wx import wx.xrc ########################################################################### ## Class doctor1 ########################################################################### class doctor1 ( wx.Frame ): def __init__( self, parent ): wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"医院电子病历信息系统", pos = wx.DefaultPosition, size = wx.Size( 1280,720 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL ) self.SetSizeHintsSz( wx.Size( 800,600 ), wx.Size( 1920,1080 ) ) bSizer1 = wx.BoxSizer( wx.VERTICAL ) bSizer1.SetMinSize( wx.Size( 800,600 ) ) self.m_button5 = wx.Button( self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 ) bSizer1.Add( self.m_button5, 0, 0, 5 ) self.m_button6 = wx.Button( self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 ) bSizer1.Add( self.m_button6, 0, 0, 5 ) self.SetSizer( bSizer1 ) self.Layout() self.Centre( wx.BOTH ) def __del__( self ): pass ########################################################################### ## Class login ########################################################################### class login ( wx.Frame ): def __init__( self, parent ): wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"医院电子病历信息系统", pos = wx.DefaultPosition, size = wx.Size( 400,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL ) self.SetSizeHintsSz( wx.Size( 400,300 ), wx.Size( 400,300 ) ) bSizer4 = wx.BoxSizer( wx.VERTICAL ) bSizer4.SetMinSize( wx.Size( 400,300 ) ) bSizer5 = wx.BoxSizer( wx.HORIZONTAL ) bSizer5.AddSpacer( ( 0, 0), 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 88 ) self.idtxt = wx.StaticText( self, wx.ID_ANY, u"帐号", wx.Point( -1,-1 ), wx.DefaultSize, 0 ) self.idtxt.Wrap( -1 ) bSizer5.Add( self.idtxt, 0, wx.ALIGN_CENTER_VERTICAL, 0 ) self.userid = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) bSizer5.Add( self.userid, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL|wx.ALIGN_CENTER_VERTICAL, 10 ) bSizer4.Add( bSizer5, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND|wx.TOP|wx.LEFT, 20 ) bSizer51 = wx.BoxSizer( wx.HORIZONTAL ) bSizer51.AddSpacer( ( 0, 0), 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 88 ) self.pwdtxt = wx.StaticText( self, wx.ID_ANY, u"密码", wx.DefaultPosition, wx.DefaultSize, 0 ) self.pwdtxt.Wrap( -1 ) bSizer51.Add( self.pwdtxt, 0, wx.ALIGN_CENTER_VERTICAL, 0 ) self.userpwd = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_PASSWORD ) bSizer51.Add( self.userpwd, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 10 ) bSizer4.Add( bSizer51, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL|wx.LEFT, 20 ) bSizer4.AddSpacer( ( 0, 0), 0, wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 10 ) bSizer61 = wx.BoxSizer( wx.HORIZONTAL ) bSizer61.AddSpacer( ( 0, 0), 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 100 ) self.radio1 = wx.RadioButton( self, wx.ID_ANY, u"挂号处", wx.DefaultPosition, wx.DefaultSize, 0 ) bSizer61.Add( self.radio1, 0, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 0 ) self.radio2 = wx.RadioButton( self, wx.ID_ANY, u"医生", wx.DefaultPosition, wx.DefaultSize, 0 ) bSizer61.Add( self.radio2, 0, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 5 ) self.radio3 = wx.RadioButton( self, wx.ID_ANY, u"管理员", wx.DefaultPosition, wx.DefaultSize, 0 ) bSizer61.Add( self.radio3, 0, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 5 ) bSizer4.Add( bSizer61, 0, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL|wx.BOTTOM|wx.LEFT, 10 ) bSizer6 = wx.BoxSizer( wx.VERTICAL ) self.online = wx.Button( self, wx.ID_ANY, u"登录", wx.DefaultPosition, wx.DefaultSize, 0 ) bSizer6.Add( self.online, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 10 ) self.offline = wx.Button( self, wx.ID_ANY, u"退出", wx.DefaultPosition, wx.DefaultSize, 0 ) bSizer6.Add( self.offline, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 ) bSizer4.Add( bSizer6, 1, wx.EXPAND|wx.TOP, 0 ) self.SetSizer( bSizer4 ) self.Layout() self.Centre( wx.BOTH ) # Connect Events self.online.Bind( wx.EVT_BUTTON, self.test ) def __del__( self ): pass # Virtual event handlers, overide them in your derived class def test( self, event ): uid=login.userid.GetValue() upwd=login.userpwd.GetValue() if uid=='123' and upwd=='321': print 'True'
刚开始学Python也没其他语言的基础,想用wxFormBuilder弄个gui然后在eclipse里绑定事件的,但是总是出错。
第二段代码的最后一段定义的test,准备绑定在登陆上的,获取帐号密码2个文本框的值。但是弹错,不知道怎么解决
Traceback (most recent call last): File "D:\eclipse\workspace\EMR\src\EMR\gui.py", line 133, in test uid=login.userid.GetValue() AttributeError: type object 'login' has no attribute 'userid'
还有,我如果想点这个按钮之后弹出另外1个窗口,并且原来的窗口自动关闭怎么弄?
test的代码有问题,因为test是在login类中,所以调用类属性时,直接使用self调用,详细修改如下:
# Virtual event handlers, overide them in your derived class def test( self, event ): uid=self.userid.GetValue() upwd=self.userpwd.GetValue() if uid=='123' and upwd=='321': print 'True' 如果想点这个按钮之后弹出另外1个窗口,并且原来的窗口自动关闭怎么弄?
一样采用事件驱动,点击该按钮时运行另外一个GUI界面的代码,同时关闭当前界面 ######非常感谢大神指点
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。