程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

19. Application and feedback of the buttons on the GUI interface of xwpython

編輯:Python

xwPython Of GUI Application and feedback of interface buttons

import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, ' The user login ', size=(400, 300))
# Create panels 
panel = wx.Panel(self)
# establish “ determine ” and “ Cancel ” Button , And bind Events 
self.bt_confirm = wx.Button(panel, label=' determine ')
self.bt_confirm.Bind(wx.EVT_BUTTON, self.OnclickSubmit)
self.bt_cancel = wx.Button(panel, label=' Cancel ')
self.bt_cancel.Bind(wx.EVT_BUTTON, self.OnclickCancel)
# Create text , Align left 
self.title = wx.StaticText(panel, label=" Please enter your user name and password ")
self.label_user = wx.StaticText(panel, label=" user name :")
self.text_user = wx.TextCtrl(panel, style=wx.TE_LEFT)
self.label_pwd = wx.StaticText(panel, label=" The secret code :")
self.text_password = wx.TextCtrl(panel, style=wx.TE_PASSWORD)
# Add containers , The controls in the container are arranged horizontally 
hsizer_user = wx.BoxSizer(wx.HORIZONTAL)
hsizer_user.Add(self.label_user, proportion=0, flag=wx.ALL, border=5)
hsizer_user.Add(self.text_user, proportion=1, flag=wx.ALL, border=5)
hsizer_pwd = wx.BoxSizer(wx.HORIZONTAL)
hsizer_pwd.Add(self.label_pwd, proportion=0, flag=wx.ALL, border=5)
hsizer_pwd.Add(self.text_password, proportion=1, flag=wx.ALL, border=5)
hsizer_button = wx.BoxSizer(wx.HORIZONTAL)
hsizer_button.Add(self.bt_confirm, proportion=0, flag=wx.ALIGN_CENTER, border=5)
hsizer_button.Add(self.bt_cancel, proportion=0, flag=wx.ALIGN_CENTER, border=5)
# Add containers , Vertical arrangement of controls in container 
vsizer_all = wx.BoxSizer(wx.VERTICAL)
vsizer_all.Add(self.title, proportion=0, flag=wx.BOTTOM | wx.TOP | wx.ALIGN_CENTER,
border=15)
vsizer_all.Add(hsizer_user, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=45)
vsizer_all.Add(hsizer_pwd, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=45)
vsizer_all.Add(hsizer_button, proportion=0, flag=wx.ALIGN_CENTER | wx.TOP, border=15)
panel.SetSizer(vsizer_all)
def OnclickSubmit(self,event):
""" Click the OK button , Execution method """
message = ""
username = self.text_user.GetValue() # Get the entered user name 
password = self.text_password.GetValue() # Get the password entered 
if username == "" or password == "" : # Determine whether the user name or password is empty 
message = ' User name or password cannot be empty '
elif username =='xiaohao' and password =='socomeon': # The user name and password are correct 
message = ' Login successful '
else:
message = ' The user name and password don't match ' # Wrong user name or password 
wx.MessageBox(message) # Pop up the prompt box 
def OnclickCancel(self,event):
""" Click the Cancel button , Execution method """
self.text_user.SetValue("") # Clear the entered user name 
self.text_password.SetValue("") # Clear the password entered 
if __name__ == '__main__':
app = wx.App() # initialization 
frame = MyFrame(parent=None,id=-1) # Instantiation MyFrame class , And pass the parameters 
frame.Show() # Display window 
app.MainLoop() # Call the main loop method 




  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved