pythongui登录界面密码显示_python的GUI之一个简单的登录界面
self代表這個類,所以要注意self的用法
先總結(jié)一下遇到的錯誤:
python positional argument follows keyword argument
位置參數(shù)在關(guān)鍵字參數(shù)之后
部分語句的關(guān)鍵字參數(shù)必須跟隨在位置參數(shù)后面
因?yàn)閜ython函數(shù)在解析參數(shù)時, 是按照順序來的,位置參數(shù)不滿足就沒辦法考慮其他的參數(shù)。
一個簡單的python GUi程序運(yùn)行時,報出錯誤 : PyNoAppError: The wx.App object must be created first!
要么把程序在python的cmd窗口運(yùn)行,不然spyder會報錯。
要么在spyder里的console輸入del app,回車,再運(yùn)行程序即可。
這個wxPython在導(dǎo)入時不用寫這么多,import wx即可
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,title='welcome',pos=(500,500),size=(200,200))
#增加面板
self.panel=wx.Panel(self)
#增加靜態(tài)文本控件
self.user=wx.StaticText(parent=self.panel,label='user',pos=(10,5),size=(80,20))
self.password=wx.StaticText(parent=self.panel,label='password',pos=(10,30),size=(80,20))
#添加文本框
self.inputN=wx.TextCtrl(parent=self.panel,pos=(80,5),size=(80,20))
self.inputM=wx.TextCtrl(parent=self.panel,pos=(80,30),size=(80,20))
#添加按鈕
self.buttonLogin=wx.Button(parent=self.panel,label='login',pos=(30,70),size=(50,20))
#為按鈕綁定事件處理方法
self.Bind(wx.EVT_BUTTON,self.login,self.buttonLogin)
#添加按鈕
self.buttonCancel=wx.Button(pos=(90,70),size=(50,20),parent=self.panel,label='cancel')
#為按鈕綁定事件處理方法
self.Bind(wx.EVT_BUTTON,self.cancel,self.buttonCancel)
#第一個參數(shù)為事件類型,第二個參數(shù)為響應(yīng)函數(shù)名,第三個參數(shù)為事件來源組件名(見上方按鈕)
def login(self,event):
name=self.inputN.GetValue()
pwd=self.inputM.GetValue()
if name=='admin' and pwd=='123456':
dlg=wx.MessageDialog(self,'注冊成功','Caution',wx.OK)
dlg.ShowModal()
else:
dlg=wx.MessageDialog(self,'注冊失敗','Caution',wx.OK)
dlg.ShowModal()
def cancel(self,event):
self.inputM.SetValue('')
self.inputN.SetValue('')
if __name__=='__main__':
app=wx.App()
frm=MyFrame()
frm.Show()
app.MainLoop()
總結(jié)
以上是生活随笔為你收集整理的pythongui登录界面密码显示_python的GUI之一个简单的登录界面的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我用男服换芒果可爱妆面亏吗
- 下一篇: java把图片写入excel_使用POI